WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
    
It is really much, much more helpful if you don't replace important parts of the code with dummy values. – s_ha_dum May 27 '13 at 15:43
up vote 3 down vote accepted

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.

add_filter('the_content', 'twitter_url',1); // run the filter very early
add_filter('the_content', 'twitter_url',100); // run the filter late

In your case, though, the two filters involved-- the ones that add twitter_url and do_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.

remove_filter('the_content', 'do_shortcode', 11); 
add_filter('the_content', 'do_shortcode', 100); 

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.

share|improve this answer
    
Thanks for the brief explanation! – Gowri May 27 '13 at 17:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.