Tuesday, May 24, 2011

Display Twitter-like “time ago” on WP

Display Twitter-like “time ago” on your WordPress blog

Twitter have a built-in function that display time from now, like “3 days ago” or “more than a month ago”.If you want to do same with your WordPress post use the following function.

Paste the following into your functions.php file:






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

Now, you can use the following function in your theme files:
 echo post_time_ago();

No comments:

Post a Comment

I just got my #domain @BigRock. Get upto 25% off with my personalized coupon link Get upto 25% off