1. Home
  2. WordPress Tutorials
  3. How to Show Relative Dates in WordPress Posts and Pages
Experience Faster, Secure and Eco-Friendly Web Hosting for your Website or Blog. Learn More.


How to Show Relative Dates in WordPress Posts and Pages

When a post or page is created, the system automatically adds a time stamp. This shows readers just when the content was created. But what if you wanted to show a relative date instead? Because WordPress hosting offers a great deal of customization, these kinds of changes are quite easy.

In this tutorial, I’ll show you how to display relative dates in WordPress as opposed to the traditional time stamp. There are two ways this can be done, and I’ll cover how to do both of them.

Why should you use relative dates in WordPress instead of the time stamp?

If you’ve noticed, a lot of news organizations and social platforms are delving more into how relative dates are being used. It gives the reader more of a sense of urgency when reading materials that are time sensitive. It also makes it easier to tell when comments or posts were recently published.

For example, a date that states it was “published yesterday” makes it seem more current than simply putting in the numerical date. This is also true if the reader doesn’t have a clue what the day is anyways. It provides more of a continuity when regarding any piece of content.

Method 1: Using the Meks Time Ago Plugin

Today, I’m going to demonstrate the Meks Time Ago plugin. It’s a simple tool that does its job and has a bit of customization when it comes to choosing how it is displayed.

To use this plugin:

Go to “Plugins” and click the “Add New” button.

Relative Date Add New

Search for “Meks Time Ago.” When the plugin is displayed, install and activate it. This will add a new function to the WordPress settings controls.

Meks Time Ago Install

Go to “Settings” in the left admin panel. General settings should be the first window that is displayed. Otherwise, click the “General” link at the top of the list.

Meks Time Ago Settings

Scroll down until you see the settings for Meks Time Ago Options. It is here where you can choose how the dates are displayed on posts.
Apply “time ago” format to: Check the boxes to determine how you want the format to be applied. This can be date, time, both or neither.
Apply to posts not older than: You can have the plugin apply the relative dates if they are younger than a certain number of months, days, hours and minutes.
Place “ago” word: The “ago” word can be placed before the relative date or after. It is up to you.
Rewrite “ago” word: Instead of using “ago,” you can alter it by putting in your own. For instance, you could put in “gone by.” I’ll use that in order to show you what it looks like.

Meks Time Ago Options

Once you’ve made your selections, click the “Save Changes” button on the bottom.

Meks Time Ago Save

Now, your website is equipped with relative dates for pages, posts and comments. If you want to set the date to show after a certain amount of time has lapsed, you can alter the “Apply to posts not older than” area.

Meks Time Ago Example

For example, setting this to “1 month” will show the correct date format after the four weeks have lapsed. Instead of the post stating “7 months ago,” it will show the correct date.

Method 2: Using Code to Add Relative Dates in WordPress

This next method I’m going to show you relies on a combination of a plugin and editing files in your WordPress theme. This is perhaps the most difficult method of the two I am demonstrating simply because each theme developer does things differently.

I’ll go into greater detail here in a moment. In a nut shell, you’ll need to sift through the files of your theme to find specific lines of code. If you’re not absolutely sure which files contain the specific code you’re looking for, it can be incredibly time consuming.

Before we get started, there are two ways you can access files for your theme that you’ll be editing. One method is using FTP programs like FileZilla to access the root directory of the web host. The other is using the WordPress built-in editor. In this tutorial, I’m going to show you how to use the latter.

It is important to note that any additions you make to your parent theme’s files can be overwritten if the developer produces an update. As a result, you may have to make these changes again in the future. I would suggest using a child theme to bypass some of these issues.

To manually enter in relative dates:

Go to the plugins area of WordPress and click the “Add New” button.

Relative Date Add New

This time, you’ll search for “WP-RelativeDate.” Once the plugin is displayed, install and activate.

WP Relative Date Activate

Here’s where it gets tricky. WP-RelativeDate does an OK job of replacing the time stamp, but it’s not always accurate. That’s because of the way it was developed. You see, every theme developer uses different file names when creating themes. This means that sometimes plugins cannot identify the code that needs to be replaced.

Go to the “Appearance” area of the WordPress dashboard and click on the “Editor.” It should be near the bottom of the list.

WP Relative Date Editor

Now comes the time consuming part. You need to find the code you need to edit from the files in the right side of the editor screen. For instance, you would need to alter the code for pages, posts and comments. So, you need to find those specific files.

WP Relative Date Files

Essentially, you’ll be looking for code similar to:

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

When you find these codes, you will need to replace them with this: <?php relative_post_the_date(); ?>

This is WP-RelativeDate’s function to change how the time stamp appears on the website.

Many theme developers will stick to a universal-style layout. Unfortunately, this isn’t always the case. Here are a few common files you may need to check:

  • Single Posts: single.php
  • Single Pages: page.php
  • Comments: comments.php

This method is simply too convoluted for many people to do. Although it does have potential to help modify the relative date of posts, pages and comments, it’s simpler to just use the plugin I mentioned at the very beginning. In reality, it’s up to you to decide which is the easiest route for your needs.

If you cannot find files that relate to the date within the content, you may have better luck using root access. Many people prefer using tools like FileZilla and cPanel’s File Manager simply because it provides complete access to WordPress as a whole. This means you can edit virtually any file in the entire system.

While the editor in WordPress gives you some access to theme files, it doesn’t provide total control like these two other platforms.

It’s all relative…

Relative dates in WordPress gives the content more of an engaging atmosphere. It denotes to the reader the passage of time while giving recent content a sense of current relevance. It’s one of the reasons why so many news and business agencies are moving to this type of a format. In any case, this is just another method that can be used to give the website an allure that keeps people interested in the content.

What kind of custom settings do you use to engage your target audience? Do you find older posts to be more popular than newer ones?

Author: Josh Dargie

My name is Josh Dargie and I’m the Operations Manager at GreenGeeks. I’ve been with the company since 2009. I have over 16 years of experience working with and for various web hosting providers specifically in development, day-to-day operations and customer service.

Updated on March 16, 2017

Was this article helpful?

Related Articles

Add A Comment