Site logo

Archived topic

adding time to read to via date output filter

5 replies · Started by Katja on August 20, 2019

Viewing posts 1–6 of 6

Hello GP Team,

I would like to add the Reading Time WP shortcode to the date output and saw the snippet provided by Tom on the following page.:
https://generatepress.com/forums/topic/add-time-to-read-in-meta-date/

Unfortunately this doesn't work for me. Instead the shortcode itself is displayed after the date.

I would like the time to be displayed in this area if possible as it keeps the meta info to one line.

Thanks for any pointers.

Best wishes,

Roger

Hi there,

Try this:

add_filter( 'generate_post_date_output', function( $output ) {
    return $output . do_shortcode( '[rt_reading_time]' );
} );

Let me know :)

Hello Tom,

that now works - thanks for your help with that.

I had another snippet from you that was also targeting the date output. the snippet made it so the date was no longer hyperlinked. (https://docs.generatepress.com/article/generate_post_date_output/#only-show-updated-date). When this snippet was active the one you provided above obviously didn't work, works fine when that one is deactivated.

If it's possible to combine the two, i.e. to have the date not hyperlinked and the reading time shortcut included that would be a great solution for me. If not, I'll leave the date hyperlinked and keep the reading time.

Thanks Tom for your brilliant service and responsiveness as always.

Best wishes,

Roger

Let's give this a shot instead:

add_filter( 'generate_post_date_output', function( $output, $time_string ) {
    $output = sprintf( '<span class="posted-on">%s</span>',
        $time_string
    );

    return $output . do_shortcode( '[rt_reading_time]' );
}, 10, 2 );

Let me know :)

Tom,

that works a treat. Thanks very much for your help.

You are just the best.

Roger

No problem! Glad I could help :)

This archived topic is closed to new replies.