Lego2012
12/13/2016 - 11:56 AM

WordPress Relative Date

WordPress Relative Date

<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.

<!-- 
Instead of displaying the date that your post was posted, you can make it relative – “6 months ago” or “3 weeks ago” or whatever. Use this in your posts/comments/pages 
-->

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