[Resolved] Adding a plugin filter to entry-meta

Home Forums Support [Resolved] Adding a plugin filter to entry-meta

Home Forums Support Adding a plugin filter to entry-meta

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1018431
    Heather Burns

    Hey there,

    I’ve installed the Insert Estimated Reading Time plugin, which outputs a simple text string. The tag to add the output is <?php estimated_reading_time(); ?>

    I want to put this into my post entry-meta, so that the output would read, for example,

    25 September 2019 ¦ Author ¦ Estimated Reading Time: x minutes

    I know this needs a custom hook, but I’m stuck on how to do it.

    Thanks!

    #1018820
    Leo
    Staff
    Customer Support

    Hi there,

    Try using the after_entry_title hook with priority 10:
    https://docs.generatepress.com/article/hooks-element-overview/

    and this as the content:
    <div class="estimated"><?php estimated_reading_time(); ?></div>

    Make sure to check execute PHP.

    Can you link me to the site after and I can provide some CSS?

    Let me know 🙂

    #1019377
    Heather Burns

    Thanks Leo, that’s the first step.

    That puts the string below where I’d like it to be. I’d like it to be in the meta (between the lines):

    https://webdevlaw.uk/2019/07/22/the-missing-pieces-teaching-the-legal-side-of-web-development/

    #1019773
    Tom
    Lead Developer
    Lead Developer

    Hey Heather,

    Right now it’s a bit of a pain, but I’ve improved it in GP 2.4 so we can hook it into the meta directly.

    For now, we can use a filter to append it to the author:

    add_filter( 'generate_post_author_output', function( $output ) {
        if ( function_exists( 'get_estimated_reading_time' ) ) {
            return $output . get_estimated_reading_time( get_the_content() );
        }
    
        return $output;
    } );

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    Let me know if that does it or not 🙂

    #1021197
    Heather Burns

    That did the trick! Thanks so much for your help.

    #1021371
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

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