WordPress filter get_the_content()

I’m writing a plugin that requires adding to the content; adding a filter to the_content() is straightforward enough, but the theme I’m testing in uses get_the_content() to build the page.
There’s an indication that it should be possible in the WordPress codex but I don’t understand the example:

If you use plugins that filter content (add_filter(‘the_content’)), then this will not apply the filters, unless you call it this way (using apply_filters):

Read More

apply_filters('the_content',get_the_content( $more_link_text, $stripteaser, $more_file ))

Can anyone help / explain?

Thanks,

David.

Related posts

Leave a Reply

2 comments

  1. What they’re saying is you’d have to add code to the place that get_the_content() is called. From your description, that’s in the theme – you’d have to change the theme’s get_the_content() call as described.

    The reason for that is that there are no filters in the get_the_content() function that you can hook into with your plugin (have a look at the source – there are no calls to the apply_filters() function in get_the_content(), except one for the “more” link text).

  2. Late to the party, but here it goes:

    In your functions.php you can add something like this:

    function do_filter_stuff($content) {
        //Whatever you want to do with your content
    }
    add_filter( 'the_content', 'do_filter_stuff' );
    

    Next, in your page.php (or whichever template you want to use it in) you can call the raw content with the same filter as following:

    <?php echo do_filter_stuff(get_the_content()); ?>