Automatically added brs and paragraphs?

Here's my very simple shortcode:

function box_shortcode( $atts, $content = null ) {
        extract( shortcode_atts( array(
            'width' => 'auto',
            'height' => 'auto', 
            ), $atts ) );  

       return '<div class="boxy-box" style="width:'. $width .'; height:'. $height .';" >'.do_shortcode($content).'</div>';

    add_shortcode('box', 'box_shortcode'); 


should give:

<div class="boxy-box" width:auto; height:auto;>something</div>

But, it doesn't. Even an empty shortcode (without a content, eg. [box][/box]) gives:

<div class="boxy-box" width:auto; height:auto;><br/></div>

(I don't care, but don't know where the br comes from)

The main problem is that, when I try [box]something[/box] I'm getting:

<div class="boxy-box" width:auto; height:auto;><br/>something<br/></div>

I know WP editor formats text automatically and there are "noP" plugins out there, but firstly - I'm using the HTML editor, secondly, why the heck WP is adding Brs (sometimes p's) to an inline code? :O

It wouldn't be a huge problem, but I HAVE to get PURE output, so:


Will give a header and a div inside my box div, without any parapgrahs, brs, spans etc.

The funny thing is I have the same shortcode with h2 instead of div and it doesn't give any brs etc.

Sometimes I'm also getting a <div class="boxy-box" width:auto; height:auto;></p>$content (...)


I've found some comments on it:

This is driving me nuts as well. What the f**k is the point of having a html/code mode for posting if wordpress filters the god damn code and wraps around the tags anyways?

So I guess that's the problem. Is there a way of turning autop functionality at least for HTML editor? ;/

Answers 3

  • You can postpone the wp_autop filter. Wordpress has this filter enabled by default. And it is processing before the shortcode output.

    remove_filter( 'the_content', 'wpautop' );
    add_filter( 'the_content', 'wpautop' , 12);

    Add this to your functions.php and check if the problem persist!

    See a similar problem here: stray <p> elements

  • I tried this:

    remove_filter( 'the_content', 'wpautop' );
    add_filter( 'the_content', 'wpautop' , 12);

    The filter works but messes up Contact Form 7

    I tried the plugin code and it worked perfect!

Related Questions