Last active
March 3, 2020 00:04
-
-
Save donnamcmaster/849fa1e87f6974565e6bc57fd9f79529 to your computer and use it in GitHub Desktop.
WordPress: filter for the_content to remove excess tags around 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
<?php | |
// get rid of junk <p> and <br> tags TinyMCE inserts around shortcodes | |
add_filter( 'the_content', function ( $content ) { | |
$array = [ | |
'<p>[' => '[', | |
']</p>' => ']', | |
']<br />' => ']', | |
']<br>' => ']', | |
'<p> </p>' => '', | |
]; | |
$content = strtr( $content, $array ); | |
return $content; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see also https://gist.github.com/donnamcmaster/b634ac4a7ebec6b3814b75d243ed23fd for processing shortcodes outside the loop