Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@donnamcmaster donnamcmaster commented May 1, 2019

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