Puddinq.com sharing knowledge
';

Ensure proper html

Ensure proper html

add_filter('the_content', 'ensureProperHtml', 20);

    function ensureProperHtml($str)
    {
        if (empty($str) === true) {
            return $str;
        }
        $doc = new \DOMDocument();
        @$doc->loadHTML(mb_convert_encoding($str, 'HTML-ENTITIES', 'UTF-8'));
        return $doc->saveHTML();
    }