''Time ago' display in Wordpress blog archive
I am attempting to change the standard Wordpress date published to 'time ago' in the blog archive, but leave the date display inside the single posts as normal.
I have found the following function from https://mekshq.com/change-wordpress-date-format-to-time-ago/ :
add_filter( 'get_the_date', 'meks_convert_to_time_ago', 10, 1 ); //override date display
add_filter( 'the_date', 'meks_convert_to_time_ago', 10, 1 ); //override date display
add_filter( 'get_the_time', 'meks_convert_to_time_ago', 10, 1 ); //override time display
add_filter( 'the_time', 'meks_convert_to_time_ago', 10, 1 ); //override time display
/* Callback function for post time and date filter hooks */
function meks_convert_to_time_ago( $orig_time ) {
global $post;
$orig_time = strtotime( $post->post_date );
return human_time_diff( $orig_time, current_time( 'timestamp' ) ).' '.__( 'ago' );
}
Of course this function applies the 'time ago' change site-wide, I would like to understand how I can have this apply only in the blog archive list view, not the single posts.
Thankyou
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
