Home / functions.php / Automatically close HTML in WYSIWYG
  • How to 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.

    wordpress snippet : PHP

    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;

    ( WordPress codex functions, hooks, in this snippet. )

    the_content, apply_filters,