DavidRobins
DavidRobins

Reputation: 31

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

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

Can anyone help / explain?

Thanks,

David.

Upvotes: 2

Views: 4905

Answers (2)

Nick van H.
Nick van H.

Reputation: 388

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()); ?>

Upvotes: 0

Hobo
Hobo

Reputation: 7611

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

Upvotes: 1

Related Questions