I have a site where a user can insert slideshows into a post by entering the shortcode in the content box. He can also add videos by adding the video code in the same box. I need to separate these two shortcodes out from each other so that I can control when the slideshows are displayed and when the videos are displayed. I'm using add_filter and preg_match to match the correct shortcode and then echo each match out - however it's currently only displaying the first match from each one. Here's my code - I'm not sure I completely understand how add_filter works, so probably have my display methods wrong:


function video_slice( $content ){
    preg_match( '/\[video.*\]/' , $content , $matches );
    if( isset( $matches ) && $matches !== "" ){
        foreach( $matches as $match ){
            return $match;

if( !has_filter('the_content') ){
  add_filter( 'the_content','video_slice');   
  add_filter( 'the_content', 'video_slice');  

I have a similar setup for the Slideshows, except my slideshow_slice function matches [SlideDeck .*] instead. How can I loop through an array of matches and print the output via the_content()?


1 Answer 1


If you don't want normal shortcode mechanics (seems like it to me from your description) why bother adding them to content at all?

Create couple of specialized meta boxes and you won't have to deal with scanning and filters at all, just store/retrieve info that you need separately to/from custom fields.

  • Yea, the method I used eventually was just to order items in the_content box rather than splitting them through several meta boxes. I think the other problem with the above was I needed to use preg_match_all().
    – lowe_22
    Commented Sep 19, 2011 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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