Created
January 25, 2015 14:26
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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