WordPress tutorials: Display twitter like time

Wpsnipp – Display twitter like time.Twitter have a really cool built-in function that display time from now, like “3 days ago” or “more than a month ago”. Doing so with WordPress is not hard using some PHP. Here is a function to do so.Adding the function to your functions.php in your wordpress theme. Then replace the_time(); in your theme with the second PHP snipp time_ago();. Time format will then display “3 days ago, more than a month” etc.

 

 

 

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

Once done, you can use the function in your theme files:

<?php
echo time_ago();
?>

Be Sociable, Share!

Leave a comment