How to Add "Time Ago" function on WordPress Posts?

2:09 AM

Need to add the post time like "15 Seconds ago" in wordpress? Here the code.

How to Add "Time Ago" function on WordPress Posts?

How to Add "Time Ago" function on WordPress Posts?
add_filter('the_time', 'dynamictime');
function dynamictime() {
global $post;
$date = $post->post_date;
$time = get_post_time('G', true, $post);
$mytime = time() - $time;
if($mytime < 60){
$mytimestamp = __('Just now');
}else{
$mytimestamp = sprintf(__('%s ago'), human_time_diff($time));
}
return $mytimestamp;
}

To print an entry's time ("2 days ago"):
human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago';

For comments:
human_time_diff( get_comment_time('U'), current_time('timestamp') ) . ' ago';

You Might Also Like

അഭിപ്രായങ്ങളൊന്നുമില്ല:

Like us on Facebook