Twitter URL plugin add the filter to the_content. This filter messing up the output of my plugin shortcode output. So I wish to remove this filter only for my shortcode output.
add_filter('the_content', 'twitter_url');
I know this can be removed using below filter
remove_filter('the_content', 'twitter_url');
But, How to apply this filter only to my shortcode output.
My shortcode
add_shortcode('xxx', 'func_xxx');
Shortcode callback function
function func_xxx(){
return 'xxx';
}
So please guide me to do this!
Filters on
the_content
are not applied on a “per shortcode” basis. Post content is passed to the first filter, and then the altered post content is passed to the second filter, and then the content altered by the first two filters is passed to the third, and so on.You can’t remove a
the_content
filter, just for your shortcode because the filters aren’t applied that way.You can sometimes avoid filter issues by manipulating the priority with which you register your filter.
In your case, though, the two filters involved– the ones that add
twitter_url
anddo_shortcodes
— where not added by you, so it is a bit more complicated and more error prone.You could have your plugin alter where
do_shortcodes
runs.And that might get you around the problem. I have done this on sites I maintain. The concern is that your plugin is altering something registered by the Core. That could potentially cause trouble for themes or other plugins.
The (probably) right answer, which is not possible to construct as you’ve posted dummy code and do not explain exactly what the Twitter plugin does to your code, is to work out what is happening to your shortcode, and why, and find a way to protect that shortcode’s content from within the plugin or from within the shortcode itself. It is possible that a small re-factoring can solve this but that means having the actual code to look at, and not some meaningless filler code.