最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

template redirect - I want to replace after WordPress is completely loaded

programmeradmin1浏览0评论

The replacement process is always done with the following code. You can also use filter hooks, but some themes are hard-coded and you can't use filters. So I'm using this code (template_redirect action) so that I can replace even hard-coded parts.

function my_replace_html($content) {

    $content = str_replace('<div class="aaa">',<div class="aaa bbb">', $content );
    return $content;

}
add_action('template_redirect', function(){ ob_start('my_replace_html'); });

However, this does not work for mobile themes set with the "Multi Device Switcher" plugin.

It has been replaced as usual with themes for PC.

HTML compression such as the "Autoptimize" plugin is also applied to the mobile theme set by the "Multi Device Switcher" plugin.

What's wrong with my method?

发布评论

评论列表(0)

  1. 暂无评论