Skip to content

Instantly share code, notes, and snippets.

@bamadesigner
Last active August 29, 2015 14:20
Show Gist options
  • Save bamadesigner/f665a367ddb2b5d8351c to your computer and use it in GitHub Desktop.
Save bamadesigner/f665a367ddb2b5d8351c to your computer and use it in GitHub Desktop.
Allows me to remove extra space, and ultimately extra <p> and <br>, from shortcodes.
// We have to remove the default shortcode filter
remove_filter( 'the_content', 'do_shortcode', 11 ); // AFTER wpautop()
// Strips extra space around and within shortcodes
add_filter( 'the_content', 'shortcode_cleanup', 11 );
function shortcode_cleanup( $content ) {
// Clean it
$content = strtr( $content, array( "\n[" => '[', "]\n" => ']', '<p>[' => '[', ']</p>' => ']', ']<br>' => ']', ']<br />' => ']' ) );
// Return the content
return do_shortcode( $content );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment