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 
it happens when your shortcode starts or it goes on multiple lines, all that plugin do is disabling wpautop (i guess)
- 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 4-5 years
- Author was Featured
- Support Staff
- Was featured in a podcast
You can also strip formatting by wrapping it in a shortcode like this.
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.
here is an example also
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…
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>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 
BTW – how does one nicely refer the author to this thread? Without calling his shortcodes wonkyFunctionally handicapped may be more politically correct.
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 );
