Skip to content

Instantly share code, notes, and snippets.

@krishna19
Forked from bitfade/gist:4555047
Created October 3, 2016 10:19
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 krishna19/050d3c0d05ddc996aa7789046f877a84 to your computer and use it in GitHub Desktop.
Save krishna19/050d3c0d05ddc996aa7789046f877a84 to your computer and use it in GitHub Desktop.
WordPress - Remove empty p tags for custom shortcodes
<?php
add_filter("the_content", "the_content_filter");
function the_content_filter($content) {
// array of custom shortcodes requiring the fix
$block = join("|",array("col","shortcode2","shortcode3"));
// opening tag
$rep = preg_replace("/(<p>)?\[($block)(\s[^\]]+)?\](<\/p>|<br \/>)?/","[$2$3]",$content);
// closing tag
$rep = preg_replace("/(<p>)?\[\/($block)](<\/p>|<br \/>)?/","[/$2]",$rep);
return $rep;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment