Hello, I am currently using the GAMEIFY template and would like to integrate a script that modifies the date, displays the duration since the post was published, and indicates the estimated reading time. I would greatly appreciate any assistance or guidance on how to accomplish this.
View attachment 28281
Bruh, the function you need in WordPress for this task is human_time_diff(). You can insert the following code at the end of your theme's functions.php file:
For posts (posted on):-
function my_timeago_post()
{
return sprintf( esc_html__( '%s ago', 'textdomain' ), human_time_diff(get_the_time ( 'U' ), current_time( 'timestamp' ) ) );
}
add_filter( 'the_time', 'my_timeago_post' );
For comments (comment date) :-
function my_timeago_comments()
{
return sprintf( esc_html__( '%s ago', 'textdomain' ), human_time_diff(get_comment_time ( 'U' ), current_time( 'timestamp' ) ) );
}
add_filter( 'get_comment_date', 'my_timeago_comments' );
This is an internal WordPress function, so consult the wp.org Codex (documentation) for more information on its usage. You can learn how to format it in specific ways based on your desired conditions, such as displaying time in weeks or days if a post is older than a certain period, among other options.