Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress: process content outside the loop; get rid of extra <p> tags around shortcodes
/* props to Thomas Griffin
https://thomasgriffin.io/remove-empty-paragraph-tags-shortcodes-wordpress/
*/
$extra_junk = array(
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']',
']<br>' => ']',
'<p>&nbsp;</p>' => '',
);
echo do_shortcode( strtr( wpautop( wptexturize( $section_content ) ), $extra_junk ) );
@donnamcmaster

This comment has been minimized.

Copy link
Owner Author

donnamcmaster commented May 1, 2019

added some more "extra junk" to the array

@donnamcmaster

This comment has been minimized.

Copy link
Owner Author

donnamcmaster commented May 1, 2019

see also https://gist.github.com/donnamcmaster/849fa1e87f6974565e6bc57fd9f79529 for filtering the_content while within the loop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.