Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

2 Answers 2

up vote 2 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

It looks like the twitter_url filter from the plugin

add_filter('the_content', 'twitter_url');

with the default priority 10, is running before the do_shortcode filter

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

with priority 11.

Original answer

where I misread the question:

Here are two ideas:

a) You could try this in your shortcode callback function:

if( function_exists( 'twitter_url' ) )
    $content = twitter_url( $content );

return $content;

b) or this in your shortcode callback function:

$content = apply_filters( 'get_shortcode_content', $content );
return $content;

where get_shortcode_content is the name of your shortcode custom filter. Then use

add_filter( 'get_shortcode_content', 'twitter_url' );

to filter the shortcode output through the twitter_url() function.

share|improve this answer
    
your answer looks directly opposite to my expactation. I want remove the filter of twitter_url function –  gowri May 27 '13 at 15:31
    
aha, I misread you wanted the opposite ;-) –  birgire May 27 '13 at 16:43

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.