Display Time Since Published in WordPress
by Bandicoot Marketing on | Posted in Tutorials | 20 comments
This is just a little snippet I discovered in the WordPress codex that allows your to display the time since your post was published. I wrote it into a little function that you can add to your functions.php file:
/** * Display time since post was published * * @uses human_time_diff() Return time difference in easy to read format * @uses get_the_time() Get the time the post was published * @uses current_time() Get the current time * * @return string Timestamp since post was published * * @author c.bavota */ function get_time_since_posted() { $time_since_posted = human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) . ' ago'; return $time_since_posted; }
Now you just need to include get_time_since_posted()
in the WordPress loop to display the time since your post was published.
Read more about human_time_diff()
at http://codex.wordpress.org/Function_Reference/human_time_diff.
20 comments for “Display Time Since Published in WordPress”