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();
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