• Posted: 2010-09-26
  • Author: Filip Stefansson
  • Tags:

Display time ago(twitter style)

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
<?php 
# For posts & pages #
echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago';
# For comments #
echo human_time_diff(get_comment_time('U'), current_time('timestamp')) . ' ago'; 

// Change to the date after a certain time
$time_difference = current_time('timestamp') - get_the_time('U');
if($time_difference < 86400) {
	//here goes the code from one of the sample above
} else {
	the_time();
};
?>

Instructions:

If you want to show how long ago something was posted(comments, post etc.), you can use WordPress human_time_diff-function. This will display something like “5 days ago“.


Share this snippet

If you like this snippet, share it with friends!