WordPress Time Ago / Days Ago (Human Time) like twitter

To print an entry’s time (“2 days ago”):

<?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?>

For comments:

<?php echo human_time_diff( get_comment_time('U'), current_time('timestamp') ) . ' ago'; ?>

Or if you want a shorter code to implement, you can add a php function in functions.php file of your theme folder:

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

and echo it as:

<?php echo time_ago(); ?>

About Steven Chu


Hi, I'm Steven! I'm an entrepreneur, photographer and art director in New York. Follow this blog for self expression, fun, and most importantly: looking comfortable, at ease, and amazing in your photos no matter who takes them! I dedicate this to my amazing friends who have let me inadvertently turn all of our hangouts and travel photos into a never ending photoshoot of fun. The proof is in the pudding-- our photos rock. My other projects: I'm the founder of InstaTechie.com, a face-to-face tech concierge service for NYC. Book a techie to walk you through something you want to learn! My work focuses on socially engaged art projects which use technology to create access to resources for communities. Visit Steven Chu Studio (stevenchustudio.com) for branding & design work or Steven Chu (stevenchu.com) for photography projects.

Leave a Reply