Archived topic
Change single post meta to updated date & reading time
2 replies · Started by Max on November 30, 2022
Hi there!
I'm currently using this code to show the updated date of the article:
add_filter('generate_post_date_show_updated_only', '__return_true');
add_filter('generate_post_date_output','gp_add_to_post_date');
function gp_add_to_post_date($output) {
return 'Updated on ' . $output;
}
And this to show the reading time of the post:
function tu_estimated_reading_time() {
$post = get_post();
$content = $post->post_content;
$wpm = 300; // How many words per minute.
$clean_content = strip_shortcodes( $content );
$clean_content = strip_tags( $clean_content );
$word_count = str_word_count( $clean_content );
$m = ceil( $word_count / 200 );
if($m < 2) {
$time = '1 min';
} else {
$time = $m . ' min';
}
return $time;
}
add_filter( 'generate_post_author_output', function( $output ) {
$output .= '<span class="read-time">— ' . tu_estimated_reading_time() . ' read </span>';
return $output;
} );
This gives me the following result:
Updated on 29 November 2022 by John Doe — 3 min read
How can I remove the 'by John Doe' part, since I'm the only author on the website? And would this negatively impact SEO in any way?
I've tried to uncheck 'Display post author' in the customizer, but the estimated reading time would then be gone too.
Thanks!
Figured it out.
I had to change generate_post_author_output in the reading time snippet to generate_post_date_output.
Then I unchecked 'Display post author' in the customizer, and it worked!
Glad to hear you found the solution!