I would like to filter the $content in my shortcode function so that all I get is the shortcode. I am trying to nest one shortcode inside another dynamically.

Here is my code

function add_slider ($atts, $content='') {

    $atts = shortcode_atts(array (
        'align' => 'center',
        'width' => '50%',
        'height' => 'auto'
    ), $atts);

  /*  foreach($videos as $video) :
             $return.='<li><a href="'.get_permalink().'">'.the_title("","",false).'</a></li>';
  if( has_shortcode( $content, 'video' ) ) {
            $content = do_shortcode($content);
       return '<ul class="bxslider">' . $content . ' </ul>';

else {
    return '<ul class="bxslider"> <li> No Videos Found In Slider </li> </ul>';
add_shortcode('slider','add_slider' );
  • It's unclear what you're asking. Please review the "How to Ask" page in our help center, and then edit your question to clarify what your desired outcome is, and detail why your currently implementation doesn't fit your needs.
    – bosco
    Apr 5, 2017 at 22:07

1 Answer 1


I solved my own issue.

I needed to filter out all the <br> and white space between my shortcode tags. WP was auto adding breaks which my functions was adding to the output of my shortcode. So I used the strip tags function to filter the $content of my shortcode

$content =  strip_tags($content);

I added this to my shortcode function and it worked like a charm!

Thanks to the people who pointed out the potential issues with the previous answer.

  • 1
    at the current form this answer has more potential in breaking many unexpected things. This is not something you can do in a plugin, and probably not something to do in a theme. This solution may be applied only to a specific site, and even than you better understand the implications Apr 6, 2017 at 14:56
  • Echo'ing what Mark said, removing wpautop won't just remove the <br> tags but will also remove the power that WordPress has to automatically add paragraph tags. Other plugins and themes may also utilize the filter and so removing WILL cause huge problems down the line.
    – Ian
    Apr 6, 2017 at 17:36
  • Mark, found a better solution. Thanks for pointing out the issue
    – Top-Bot
    Apr 8, 2017 at 1:51
  • Upvoting because your new solution is a lot better than the initial version and your question is a lot clearer!
    – Ian
    Apr 8, 2017 at 3:13

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.