[Resolved] adding time to read to via date output filter

Home Forums Support [Resolved] adding time to read to via date output filter

Home Forums Support adding time to read to via date output filter

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #989032
    Katja

    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

    #989295
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try this:

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

    Let me know πŸ™‚

    #989448
    Katja

    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

    #989906
    Tom
    Lead Developer
    Lead Developer

    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 πŸ™‚

    #990761
    Katja

    Tom,

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

    You are just the best.

    Roger

    #991158
    Tom
    Lead Developer
    Lead Developer

    No problem! Glad I could help πŸ™‚

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