Skip to content

Instantly share code, notes, and snippets.

@tahirtaous
Created January 25, 2015 14:26
Show Gist options
  • Save tahirtaous/dbb6a055921714e66a4c to your computer and use it in GitHub Desktop.
Save tahirtaous/dbb6a055921714e66a4c to your computer and use it in GitHub Desktop.
This function outputs the difference between two timestamps and is presented in a human readable format like “10 mins”, “1 hour”, “3 days”. It has some similarity with the popular Twitter “time ago” function, and is considered to be quite useful for displaying when the post was last modified.
// Source: https://www.cms2cms.com/blog/6-useful-yet-relatively-unknown-wordpress-functions/
// This function will generate something like this
// This post was published 2 weeks ago
// Tested : WordPress 4.1
<?php
echo 'This post was published ' . human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) . ' ago';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment