shortcode – wpv-human-diff

The WordPress human_time_diff() function returns the difference between two timestamps in a human readable format such as “1 hour”, “5 mins”, “2 days”. It is possible to use it to build a shortcode to display how long time a post was posted:

// human_time_diff shortcode
add_shortcode( 'wpv-human-diff', 'human_diff_func' );
function human_diff_func( $atts ) {
return human_time_diff( get_the_time('U'), current_time('timestamp') );

Then I can use this shortcode anywhere:


human_time_diff() reference:

You can find this solution on this Toolset forum thread:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>