548 posts
  • Bought between 100 and 499 items
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
tonvie says

I love the theme I’m working with right now but the shortcodes are leaving behind empty paragraph tags thus messing up spacing. Probably old news but it took me a bit of Googling…this plugin works a treat if you’re having this issue :)

http://www.johannheyne.de/wordpress/shortcode-empty-paragraph-fix/
238 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 4-5 years
ewizz says

it happens when your shortcode starts or it goes on multiple lines, all that plugin do is disabling wpautop (i guess)

674 posts
  • Has attended an Envato Live event
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Referred between 500 and 999 users
  • Envato Staff
  • Author had a File in an Envato Bundle
  • Has been a member for 5-6 years
  • Support Staff
+7 more
cudazi Staff says

You can also strip formatting by wrapping it in a shortcode like this.

382 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 3-4 years
MelforDMThemes says

Better to add a code where unwanted p, br and such are removed automatically from the shortcodes only, so no need for a double shortcode and no need for a wp auto p removal which will lead to unwanted formatting errors at well.

That’s just how I do it.

701 posts
  • Bought between 1000 and 4999 items
  • Canada
  • Has been a member for 6-7 years
  • Referred between 1 and 9 users
chrismccoy says
https://gist.github.com/1135818

here is an example also

548 posts
  • Bought between 100 and 499 items
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
tonvie says

Thanks for replies folks. Do you mean I would be better off hard coding something in the functions.php file for each shortcode? I’m confused…

438 posts
  • Exclusive Author
  • Has been a member for 3-4 years
  • United States
christopherjon says
Thanks for replies folks. Do you mean I would be better off hard coding something in the functions.php file for each shortcode? I’m confused…
Yeah,

Your theme has wonky poorly written shortcode.

You’ll want something like…

$content = preg_replace('#^<\/p>|<p>$#', '', $content);</p>

I think that is the correct code. I honestly haven’t written or used shortcode in over a year so I had to dig back into the archives.

The preg_replace is what your missing. It automatically removes the P’s from the shortcode without messing with core wp stuff.

Here is a complete shortcode to put the above code into context.

function clone_box_basic( $atts, $content = null ) { $content = preg_replace('#^<\/p>|<p>$#', '', $content); return '<div class="basic_box">' . do_shortcode($content) . '</div>'; } add_shortcode('box_basic', 'clone_box_basic'); </p>
548 posts
  • Bought between 100 and 499 items
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
tonvie says
christopherjon said
Thanks for replies folks. Do you mean I would be better off hard coding something in the functions.php file for each shortcode? I’m confused…
Yeah,

Your theme has wonky poorly written shortcode.

You’ll want something like…

$content = preg_replace('#^<\/p>|

$#’, ’’, $content);

I think that is the correct code. I honestly haven’t written or used shortcode in over a year so I had to dig back into the archives.

The preg_replace is what your missing. It automatically removes the P’s from the shortcode without messing with core wp stuff.

Here is a complete shortcode to put the above code into context.

function clone_box_basic( $atts, $content = null ) { $content = preg_replace('#^<\/p>|

$#’, ’’, $content); return ‘

’ . do_shortcode($content) . ‘ ’; } add_shortcode(‘box_basic’, ‘clone_box_basic’);

Ok, thanks! I thought I was on the right track with preg_replace from what I read at a few sites…that gives me a direction to go. I’d love to fix this myself if at all possible. Enough info to be dangerous anyway ;)

BTW – how does one nicely refer the author to this thread? Without calling his shortcodes wonky :D

438 posts
  • Exclusive Author
  • Has been a member for 3-4 years
  • United States
christopherjon says
BTW – how does one nicely refer the author to this thread? Without calling his shortcodes wonky
Functionally handicapped may be more politically correct.
3195 posts
  • Sold between 5 000 and 10 000 dollars
  • United States
  • Bought between 10 and 49 items
  • Has been a member for 4-5 years
  • Exclusive Author
organicbee says

you’ll want to use something like

//Clean Up WordPress Shortcode Formatting - important for nested shortcodes
//adjusted from http://donalmacarthur.com/articles/cleaning-up-wordpress-shortcode-formatting/
function parse_shortcode_content( $content ) {

   /* Parse nested shortcodes and add formatting. */
    $content = trim( do_shortcode( shortcode_unautop( $content ) ) );

    /* Remove '' from the start of the string. */
    if ( substr( $content, 0, 4 ) == '' )
        $content = substr( $content, 4 );

    /* Remove '' from the end of the string. */
    if ( substr( $content, -3, 3 ) == '' )
        $content = substr( $content, 0, -3 );

    /* Remove any instances of ''. */
    $content = str_replace( array( '<p></p>' ), '', $content );
    $content = str_replace( array( '<p>  </p>' ), '', $content );

    return $content;
}

//move wpautop filter to AFTER shortcode is processed
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 99);
add_filter( 'the_content', 'shortcode_unautop',100 );
by
by
by
by
by
by