Created
April 24, 2014 16:01
-
-
Save jawinn/11259917 to your computer and use it in GitHub Desktop.
Remove Empty Paragraphs from Shortcodes, WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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