Skip to content

Instantly share code, notes, and snippets.

@benjaminsinger
Created June 24, 2015 14:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjaminsinger/c66600e43ffe3c7531de to your computer and use it in GitHub Desktop.
Save benjaminsinger/c66600e43ffe3c7531de to your computer and use it in GitHub Desktop.
Sanitize Wordpress WYSIWYG output
function sanitize_content($content) {
$block = join("|",array("make_columns", "make_row"));
$rep = preg_replace("/(<p>)?\[($block)(\s[^\]]+)?\](<\/p>|<br \/>)?/","[$2$3]",$content);
$rep = preg_replace("/(<p>)?\[\/($block)](<\/p>|<br \/>)?/","[/$2]",$rep);
return $rep;
}
add_filter("the_content", "sanitize_content");
add_filter("the_field", "sanitize_content");
add_filter("acf_the_content", "sanitize_content");
remove_filter ('acf_the_content', 'wpautop'); /* remove the automatic paragraph enclosure of anchor tags */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment