Automatically close HTML in WYSIWYG

Adding this PHP code to the functions.php of your wordpress theme will automatically close any missing tags when using the WYSIWYG editor.

 

 

function clean_bad_content($bPrint = false) {
global $post;
$szPostContent  = $post->post_content;
$szRemoveFilter = array("~<p[^>]*>s?</p>~", "~<a[^>]*>s?</a>~", "~<font[^>]*>~", "~</font>~", "~style="[^"]*"~", "~<span[^>]*>s?</span>~");
$szPostContent  = preg_replace($szRemoveFilter, '', $szPostContent);
$szPostContent  = apply_filters('the_content', $szPostContent);
if ($bPrint == false) return $szPostContent;
else echo $szPostContent;
}

Be Sociable, Share!

Leave a comment