Hi there,
I need to output a string from a text editor. I always apply the default ‘the_content’ filter to it to render shortcodes etc.:
apply_filters( 'the_content', $mystring );
However, when the Page Builder is activated in the default editor, this always returns the content of that editor, not the rendered string $mystring.
I think this must be a bug, maybe you can tell me how to work around it.
Thanks!
Hi Paddelboot
Thanks for reaching out. Page Builder outputs via
so it isn’t a bug. Do you need to use the
or could you perhaps rather use something like:
Hi Andrew,
Unfortunately I need to apply the the_content filter on it, for parsing shortcodes or media embed URLs etc.
I don’t think Page Builder should “appropriate” this filter completely. Imagine someone who adds a second WP Editor to a custom post type editor screen. The filters applied to this content would have to be the same as for the main content, right?
Thanks!
Hi Paddelboot
You can think of the_content filter being for $post->post_content and the_content() function. Technically there’s no other way for us to take over the_content() function, without using the_content filter. The only other option would be for us to forces themes to add a separate function that we could use, or to store Page Builder content in $post->post_content as shortcodes. This is the approach some other plugins take, but in general, it seems like people are against that approach.
WordPress should possibly have offered 2 filters. One filter called maybe text_content that filters generic text content, and another one that filters the output of the_content() function.
It’s open to interpretation, but to me, the_content filter implies that it’s a filter for a single thing – being the post content, which WordPress calls the_content. Just the same as the_excerpt would refer specifically to a post’s excerpt, rather than generic excerpt/summary text and the_title filter would refer to a posts title, rather than generic title strings.
To create your own filter for your plugin, you could look at default-filters.php and copy out all the filters that are applied to the_content and rename them to something like myplugin_content.
This would give you far more control over which filter functions are applied.
I hope that clarifies things, and our thinking on using the_content filter. Answering it as fully as I can, because it is a question that comes up from time to time :)
If you need to use `the_content` filter you should remove the Site Origin content filter ( and re-add it after you’re finished ):
Then when you need it, maybe above a loop, you can re-add this filter: