Site logo

[Resolved] Change single post meta to updated date & reading time

Home Forums Support [Resolved] Change single post meta to updated date & reading time

Home Forums Support Change single post meta to updated date & reading time

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #2442607
    Max

    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!

    #2442637
    Max

    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!

    #2442798
    David
    Staff
    Customer Support

    Glad to hear you found the solution!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.