548 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has collected 100+ items on Envato Market
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
  • Has been part of the Envato Community for over 4 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
ewizz says

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

676 posts
  • Has referred 500+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Joined us in one of our Envato Live Events
+11 more
cudazi Envato team says

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

382 posts
  • Has been part of the Envato Community for over 3 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
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
  • Has been part of the Envato Community for over 6 years
  • Has referred 1+ members
  • Located in Canada
  • Has collected more than 1000 items on Envato Market
chrismccoy says
https://gist.github.com/1135818

here is an example also

548 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has collected 100+ items on Envato Market
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
  • Has been part of the Envato Community for over 3 years
  • Sells items exclusively on Envato Market
  • Located in 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
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has collected 100+ items on Envato Market
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
  • Has been part of the Envato Community for over 3 years
  • Sells items exclusively on Envato Market
  • Located in 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.
3243 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 more
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