Skip to content

Instantly share code, notes, and snippets.

@donnamcmaster
Last active May 1, 2019 19:07
Show Gist options
  • Save donnamcmaster/b634ac4a7ebec6b3814b75d243ed23fd to your computer and use it in GitHub Desktop.
Save donnamcmaster/b634ac4a7ebec6b3814b75d243ed23fd to your computer and use it in GitHub Desktop.
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
Copy link
Author

added some more "extra junk" to the array

@donnamcmaster
Copy link
Author

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