Skip to content

Instantly share code, notes, and snippets.

@jawinn
Created April 24, 2014 16:01
Show Gist options
  • Select an option

  • Save jawinn/11259917 to your computer and use it in GitHub Desktop.

Select an option

Save jawinn/11259917 to your computer and use it in GitHub Desktop.
Remove Empty Paragraphs from Shortcodes, WordPress
<?php
// http://webandphp.com/remove-markup-from-wordpress-shortcodes
/**
* Removes mismatched </p> and <p> tags from a string
*
* @author Jason Lengstorf <jason@copterlabs.com>
*/
function copter_remove_crappy_markup( $string )
{
$patterns = array(
'#^\s*</p>#',
'#<p>\s*$#'
);
return preg_replace($patterns, '', $string);
}
// USE IN SHORTCODE. EXAMPLE:
function my_shortcode_highlight( $attr, $content )
{
$clean = copter_remove_crappy_markup($content);
return '<div class="highlight">' . $clean . '</div>';
}
add_shortcode('highlight', 'my_shortcode_highlight');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment