customization - Cannot replace header & footer using “the_content”

It replace everything except header & footer. I've tried different priority for this function but it doesn'

It replace everything except header & footer. I've tried different priority for this function but it doesn't seem to work.

I think the_content is only for content and not header/footer, but after reading documentation, I still cannot find what else to use.

function add_lazyload($content) {

    $content = mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8");
    $dom = new DOMDocument();
    @$dom->loadHTML($content);

    foreach ($dom->getElementsByTagName('img') as $node) {  
        $oldsrc = $node->getAttribute('src');
        $node->setAttribute("data-src", $oldsrc );
        $newsrc = null;
        $node->setAttribute("src", $newsrc);
    }
    $newHtml = preg_replace('/^<!DOCTYPE.+?>/', '', str_replace( array('<html>', '</html>', '<body>', '</body>'), array('', '', '', ''), $dom->saveHTML()));
    return $newHtml;
}
add_filter('the_content', 'add_lazyload');

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745344648a4623486.html

相关推荐

  • customization - Cannot replace header &amp; footer using “the_content”

    It replace everything except header & footer. I've tried different priority for this function but it doesn'

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信