The context is the [caption] shortcode found in media.php which contains img_caption_shortcode

img_caption_shortcode also includes these lines:

 $output = apply_filters('img_caption_shortcode', '', $attr, $content);
 if ( $output != '' )
 return $output;

I'm trying to manipulate the output the caption shortcode and it struck me that I could filter the function or I could add_shortcode to replace it - is there any difference? and if so what would are the tradeoffs?

Many thanks in advance.


add_shortcode() may be overwritten, dependent upon at what point it is hooked, whereas you would have to remove_filter() to prevent the filter from executing. I think the way to go is to use apply_filters(), as that functionality is clearly put in place to do exactly what you're trying to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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