2. Using post time and date WordPress filter hooks
This solution is more suitable for those who don’t want to change the theme template files. In the following example we are using a callback function to override built in WordPress get_the_date and get_the_time functions and display time ago format automatically.
add_filter( ‘get_the_date’, ‘meks_convert_to_time_ago’, 10, 1 ); //override date display
add_filter( ‘the_date’, ‘meks_convert_to_time_ago’, 10, 1 ); //override date display
add_filter( ‘get_the_time’, ‘meks_convert_to_time_ago’, 10, 1 ); //override time display
add_filter( ‘the_time’, ‘meks_convert_to_time_ago’, 10, 1 ); //override time display
/* Callback function for post time and date filter hooks */
function meks_convert_to_time_ago( $orig_time ) {
global $post;
$orig_time = strtotime( $post->post_date );
return human_time_diff( $orig_time, current_time( ‘timestamp’ ) ).’ ‘.__( ‘ago’ );
}
add_filter( ‘get_the_date’, ‘meks_convert_to_time_ago’, 10, 1 ); //override date display
add_filter( ‘the_date’, ‘meks_convert_to_time_ago’, 10, 1 ); //override date display
add_filter( ‘get_the_time’, ‘meks_convert_to_time_ago’, 10, 1 ); //override time display
add_filter( ‘the_time’, ‘meks_convert_to_time_ago’, 10, 1 ); //override time display
/* Callback function for post time and date filter hooks */
function meks_convert_to_time_ago( $orig_time ) {
global $post;
$orig_time = strtotime( $post->post_date );
return human_time_diff( $orig_time, current_time( ‘timestamp’ ) ).’ ‘.__( ‘ago’ );
}
That’s it! Just paste this snippet in you theme functions.php file. Also, depending of your theme code and logic, you may only want to use time OR date filters so you can remove unnecessary hooks optionally.
3. Using Meks Time Ago WordPress plugin
For all of you who are not familiar with coding we have created a plugin which will change your post date format to time ago and should work with any theme out of the box. Meks Time Ago WordPress plugin is 100% free and can be downloaded from official WordPress plugin repository.
Once you install and activate the plugin you can go and manage its simple options. The sweetest thing here is the limitation option so you can apply time ago format only for posts which are not older than specific time frame. For example, let’s say that you want to show time ago date format only for posts which are published in the last 5 days while other posts will be displayed in standard date format.
meks_time_ago_options
Live example?
Yes, we are using this “time ago” approach in our several WordPress themes so you can see it live in action on our demo websites for Voice Theme, Throne Theme, and Sidewalk Theme. Feel free to try and let us know what do you think in comments section.
GIPHY App Key not set. Please check settings