Site logo

Archived topic

Reading Time Help needed

3 replies · Started by Jerry on January 2, 2021

Viewing posts 1–4 of 4

Hi guys,
I have used this code to add estimated reading time to be added.

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 );
    $time = ceil( $word_count / $wpm );
    
    if ($time == 1) {
        return $time . ' min read';
    } else {
        return $time . ' mins read';
    }
}
add_action( 'generate_post_meta_items', function( $item ) {
    if ( 'reading-time' === $item ) {
        echo '<span class="reading-time"> ' . tu_estimated_reading_time() . '</span>';
    }
} );

add_filter( 'generate_header_entry_meta_items', function() {
    return array(
        'author',
        'date',
        'reading-time',
    );
} );

It is almost doing what I like it to do. However, I'd like to add space between the "date" and the byline.

The "byline" and "time left to read" has that space so essentially I'd like to achieve this:

DATE SPACE BYLINE SPACE READ_TIME

You can see it here if needed, thank you guys!
https://tinyurl.com/y7l3alv7

http://jeroenc2.sg-host.com/blog/

Hi there,

i am not seeing the author byline in the meta ? So do you just want more space between the date | reading time ? If so edit this CSS:

.byline, .posted-on, .comments-link {
    border-right: 2px solid #ddd;
    padding-right: 1px;
}

And increase the padding-right: 1px; to 5px or whatever space you need.

Let me know.

Hi David,
Yes that worked. Sometimes the simplest things are right under your nose, thank you!

Glad to be of help

This archived topic is closed to new replies.