【问题标题】:Custom style sheet tag in wordpresswordpress 中的自定义样式表标签
【发布时间】:2016-07-12 19:17:33
【问题描述】:

我想在 wordpress 中自定义样式表代码。

global $is_chrome;
if($is_chrome){
    add_filter("style_loader_tag", function($tag){
        return str_replace("rel='stylesheet' " ,"rel='preload' as='style' onload=\"this.rel='stylesheet'\" ",  $tag);
    });
}

但这对资产文件夹中的 css 有效。 这对 [themes > mytheme > ooo.css] 不利。

我怎样才能度过这个难关。

提前谢谢你。

【问题讨论】:

    标签: css wordpress stylesheet add-filter


    【解决方案1】:

    加入样式是在 WordPress 中添加样式表的正确方法

    将以下代码粘贴到functions.php 并将pathfilename.css更改为您的pathfilename

       function themename_enqueue_style() {
            wp_enqueue_style( 'customCSS', get_template_directory_uri() . '/path/filename.css' ); 
        }
        add_action( 'wp_enqueue_scripts', 'themename_enqueue_style' );
    

    get_template_directory_uri() 打印 模板目录 链接。

    示例: www.example.com/wp-content/themes/themename

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-29
      • 2012-01-31
      相关资源
      最近更新 更多