Skip to content

Instantly share code, notes, and snippets.

@donnamcmaster
Last active March 3, 2020 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donnamcmaster/849fa1e87f6974565e6bc57fd9f79529 to your computer and use it in GitHub Desktop.
Save donnamcmaster/849fa1e87f6974565e6bc57fd9f79529 to your computer and use it in GitHub Desktop.
WordPress: filter for the_content to remove excess tags around shortcodes
<?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>&nbsp;</p>' => '',
];
$content = strtr( $content, $array );
return $content;
});
@donnamcmaster
Copy link
Author

see also https://gist.github.com/donnamcmaster/b634ac4a7ebec6b3814b75d243ed23fd for processing shortcodes outside the loop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment