-
-
Save joshuafredrickson/dc1b469f34908a8b7da1 to your computer and use it in GitHub Desktop.
Remove empty p tags for custom shortcodes
This file contains 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
// Remove empty p tags for custom shortcodes | |
add_filter('the_content', 'op_content_filter'); | |
function op_content_filter($content) { | |
// array of custom shortcodes requiring the fix | |
$block = join('|',array('shortcode1')); | |
// opening tag | |
$rep = preg_replace("/(<p>)?\[($block)(\s[^\]]+)?\](<\/p>|<br \/>)?/","[$2$3]",$content); | |
// closing tag | |
$rep = preg_replace("/(<p>)?\[\/($block)](<\/p>|<br \/>)?/","[/$2]",$rep); | |
return $rep; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment