WordPress.org

Plugin Directory

!This plugin hasn’t been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.

Relative Date Template Tag

Gives developers two template tags for retrieving a relative date instead of an exact date for posts.

Options

When calling either template tag you can pass a few optional parameters via an array to customize the value that is returned.

Example:

<?php //print relative date as "X periods ago"
//where periods is the largest time period that can be calculated for the current post where X >= 1
the_relative_date(); ?>

Example:

<?php //retrieve relative date as "X periods ago"
//where periods is the largest time period that can be calculated for the current post where X >= 1
get_the_relative_date(); ?>

Example:

<?php //relative date args
$params = array(
    'period' => 'minutes'
);

//get relative date as "X minutes ago"
get_the_relative_date($params);

Example:

$params = array(
    'period' => 'days',
    'suffix' => 'before now',
    'id' => 22
);

//prints relative date for post with ID 22 as "X days before now"
the_relative_date($params);

Relative Time

The template tags will return the time relative to the timezone set in WordPress' General Settings and will return the largest time period that it can, unless the $period parameter is set. If the $period parameter is set, but the post wasn't posted at least 1 $period ago, the template tag will return the largest time period that it can calculate for the post.

Acceptable 'period' values (the returned string will be de-pluralized if needed):

  • 'seconds'
  • 'minutes'
  • 'hours'
  • 'days'
  • 'weeks'
  • 'months'
  • 'years'
  • 'decades'
  • 'centuries'
  • 'millenia'

Support

Please use the Plug-in's github page for reporting any issues or asking questions.

Requires: 3.5.0 or higher
Compatible up to: 3.5.2
Last Updated: 3 years ago
Active Installs: 20+

Ratings

0 out of 5 stars

Support

Got something to say? Need help?

Compatibility

+
=
Not enough data

0 people say it works.
0 people say it's broken.