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:
Videos:
/* VIDEO SLICE */
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');
}else{
remove_filter('the_content','slidedeck_slice');
add_filter( 'the_content', 'video_slice');
}
the_content();
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()
?
Thanks