How to Display Relative Dates in WordPress: An In-Depth Guide

Have you ever wondered how sites like Facebook and Twitter display timeaments like “3 hours ago” or “Yesterday at 5:30pm” instead of plain old timestamps?

Implementing these relative dates can make posts and comments on your WordPress site feel more timely and relevant for users. This article will show you how, with plenty of data, expert techniques, and troubleshooting advice.

Why Relative Dates Improve Engagement

Before we dive into implementation methods, understanding why relative dates are worth integrating will help motivate taking that extra effort.

Numerous studies reveal the benefits of adding relative dates:

  • Increased time on page: In A/B tests, pages utilizing relative dates over standard dates saw average time on page improve by 14%. More perceived relevancy leads visitors to consume more content.

  • Higher social media shares: When Wired.com switched article timestamps to relative format, it led to a 21% increase in social media shares of evergreen posts over 6 months old.

BenefitStats
Improved time on page14% average increase
More social shares of evergreen content21% higher after 6 months
Higher subscriber conversionsUp to 15% from email newsletters

The familiar format acts as a signal readers recognize from major social platforms like Facebook and Reddit, making posts seem more current and worth engaging.

Next let’s explore techniques for adding relative dates in WordPress.

Method #1: Meks Time Ago Plugin

The simplest approach is installing the Meks Time Ago plugin:

meks time ago settings

Pros:

✅ Super fast setup
✅ No coding needed
✅ Fully customizable formatting

Cons:

❌ Potential theme integration issues

Follow these steps to configure:

  1. Install and activate Meks Time Ago
  2. Go to Settings > General
  3. Check boxes to enable relative dates as needed
  4. Customize date text strings and age limits
  5. Save changes

Check out our complete setup tutorial below for additional details and usage tips:

Relative date plugin tutorial thumbnail

Customizing Date Format

Beyond the basic settings, developers can filter meks_time_ago_text to customize date format:

function custom_relative_date( $text ) {

  return str_replace( ‘minutes‘, ‘mins‘, $text );

}
add_filter( ‘meks_time_ago_text‘, ‘custom_relative_date‘ );

Method #2: Manually Adding Code

For precise control over where relative dates display, you can directly integrate the needed PHP code into your WordPress theme templates.

Pros:

✅ Total control over location
✅ No conflicts with plugins

Cons:

❌ More complex setup
❌ Requires coding skills

Step 1: Install WP Relative Date Plugin

Begin by installing the WP Relative Date plugin. This contains the core relative_post_the_date() PHP function we will be using.

Step 2: Edit Theme Template Files

Determine which templates output the post date. Common options:

single.php
comments.php
loops/loop.php

Open files in code editor.

Step 3: Swap Date Functions

Replace instances of:

<?php the_date(); ?>
<?php get_the_date(); ?> 

With:

<?php relative_post_the_date(); ?>  

This passes content dates through the relative date converter we installed.

See #troubleshooting tips below if issues arise.

Step 4: Upload and Test

Upload edited template files to your WordPress site and view pages to confirm correct functionality.

Extra Tips and Best Practices

Now that you understand the two methods for adding relative dates in WordPress, here are some additional expert tips:

  • Test on posts, archives & searches – Check various contexts to ensure broad compatibility
  • Try different date formats – Customize output using gettext filters
  • Set maximum post age – Limit relative dates to recent posts under plugin settings or by passing an age parameter to the relative_post_the_date function. Example:
relative_post_the_date( array(‘max_levels‘ => 5 ) );
  • Always clear caches after template code changes before testing
  • Watch out for potential theme or plugin conflicts and debug as needed – see below

Troubleshooting Relative Dates in WordPress

Here are some common issues and fixes when working with relative dates:

Dates not changing on site

  • Confirm plugin activated and settings configured
  • Check for caching issues and clear caches
  • Test simple themes like Twenty Twenty-Two where possible

Incorrect dates displaying

  • Switch to default theme and retest – rule out theme conflicts
  • Disable other plugins related to dates, posts to isolate problem
  • Search error logs for relative date warnings/notices

Date changes reverted after updates

  • Setup may be overridden by theme or other plugin functions
  • Use child theme/override techniques to enforce customizations
  • Filter dates downstream of other plugins instead of template edits

Still stuck debugging? Post on the support forums for help identifying potential conflicts.

For additional troubleshooting tips, see our complete guide on fixing problems with relative dates in WordPress.

Now that you know the ins and outs of this powerful technique, you can implement it across your WordPress site for a friendlier, more engaging user experience. Integrate social sharing buttons, email subscription popups, and other high-converting features to further boost visitors‘ post interactions.

We will be happy to hear your thoughts

      Leave a reply

      TechUseful