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:

[wpv-human-diff]


human_time_diff() reference: https://developer.wordpress.org/reference/functions/human_time_diff/

You can find this solution on this Toolset forum thread:

https://toolset.com/forums/topic/date-display-problem/