thundernet8 / Tint-Pro

WordPress高级扩展主题Tinection Two/Tint
https://webapproach.net
GNU General Public License v3.0
44 stars 12 forks source link

[问题]主题缓存似乎对页面进行了二次处理 #11

Open fantastlcok opened 7 years ago

fantastlcok commented 7 years ago

使用某短代码插件,此插件需要加载自己的css和js。 在文章内使用短代码后,第一次打开文章页面正常显示。第二次打开,页面没有加载短代码css、js。 清理主题缓存后再打开页面,正常显示。再次打开,页面没有加载短代码资源。


我尝试自己在页面内引入代码,但似乎引入的代码没有任何效果。我确保引入的代码确实被加载了。

function myxxxCss() {  
        wp_register_style( 'xxx', '/wp-content/themes/Tint/assets/css/xxx.css', false, false, true );
        wp_register_style( 'box_shortcodes', '/wp-content/plugins/shortcodes-ultimate/assets/css/box-shortcodes.css', false, false, true );
        wp_register_script( 'jquery', '//staticfile.qnssl.com/jquery/2.2.1/jquery.min.js');
        wp_register_script( 'other_shortcodes', '/wp-content/plugins/shortcodes-ultimate/assets/js/other-shortcodes.js', array('jquery'), false, true );
        wp_deregister_script( 'jquery' );
        if ( !is_admin() ) { /** Load Scripts and Style on Website Only */
            wp_enqueue_style( 'xxx' ); 
            wp_enqueue_style( 'box_shortcodes' );
            wp_enqueue_script( 'jquery' );
            wp_enqueue_script( 'other_shortcodes' ); 
        }  
}
add_action( 'init', 'myxxxCss' );

http://ww1.sinaimg.cn/large/ec76730dgy1fcsdh5xqisj208f0anaag.jpg 例如其中xxx.css内有样式

#header-menu i.tico {
    margin-right: 10px;
}

但根本没有任何效果,如果我手动直接在页脚载入则没有任何问题。

<link rel="stylesheet" type="text/css" href="https://hegou.*******/wp-content/themes/Tint/assets/css/xxx.css">
thundernet8 commented 7 years ago

你首先

wp_register_script( 'jquery', '//staticfile.qnssl.com/jquery/2.2.1/jquery.min.js');

注册了jquery,然后

wp_deregister_script( 'jquery' );

注销了jquery, 所以我测试是后面几个wp_enqueue_script,前两个可以执行,而第三个因为执行被注销的jquery,其报错,同样导致后面第四个执行被取消

fantastlcok commented 7 years ago

@thundernet8 我只添加代码

function myxxxCss() {  
        wp_register_style( 'xxx', '/wp-content/themes/Tint/assets/css/xx-vb45h7y95h.css', false, false, true );
        if ( !is_admin() ) { 
            wp_enqueue_style( 'xxx' ); 
        }  
}
add_action( 'init', 'myxxxCss' );

毫无疑问,css确实加载了。 http://ww1.sinaimg.cn/large/ec76730dgy1fctujknolbj206w040jrd.jpg 但是样式并没有效果。 然后开启主题缓存,在第一次访问页面插件正常加载了文件后,第二次访问插件就无法加载文件了。我开启主题的禁用缓存可以解决这个问题。