Most of the templates for WordPress displays author info, tags, date and sometimes time also in every posts. If you had ever thought of displaying time in facebook style, here is a solution for you.

Open functions.php, from the themes folder, fot the theme you wish to use this feature and add these lines.

function timeago( $type = 'post' ) {
	$d = 'comment' == $type ? 'get_comment_time' : 'get_post_time';
	return human_time_diff($d('U'), current_time('timestamp')) . " " . __('ago');

then save your functions.php. This function will return the time ago the post was published. Add the following line wherever you need to display time ago.

<?php echo timeago(); ?>

You can add this to your single.php – usually for single posts or comments.php – for comments. Usage depends on your template design and the area of need.

Display “Time Ago” for Posts and Comments in WordPress
Tagged on:             


3D modeler and Web designer. Founder of Techlister. Love to build sites using Wordpress and Joomla. Interested in Astronomy.

2 thoughts on “Display “Time Ago” for Posts and Comments in WordPress

  • Aug 23, 2014 at 12:37 pm

    Hello there,
    It is possible to add the word “ago” in front of the current time?
    I have my WP in romanian language and it says “17 ore ago” ,which does not look good, should be “acum 17 ore” (acum means ago).

    • Aug 23, 2014 at 12:48 pm

      replace this line
      return human_time_diff($d(‘U’), current_time(‘timestamp’)) . ” ” . __(‘ago’);

      with this

      return “acum “. human_time_diff($d(‘U’), current_time(‘timestamp’)) .” ore”;


Leave a Reply

Your email address will not be published. Required fields are marked *