Site logo

Archived topic

Adding a plugin filter to entry-meta

5 replies · Started by Heather Burns on September 25, 2019

Viewing posts 1–6 of 6

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!

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 :)

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 :)

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

You're welcome :)

This archived topic is closed to new replies.