css - wordpress中的自定义样式表标签

标签 css wordpress stylesheet add-filter

我想在 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);
    });
}

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

我怎样才能度过难关。

提前谢谢你。

最佳答案

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

将下面的代码粘贴到 functions.php 并将 pathfilename.css 更改为您的 path文件名

   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

关于css - wordpress中的自定义样式表标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38326802/

相关文章:

html - 更改 bootstrap 3 中的堆叠顺序

javascript - 需要清空一个 div 但在 div 中只保留几个 div 但保留那里的 jquery 单击功能

html - 如何删除 wordpress 主题中横幅和内容之间的空格?

php - wordpress-action hook 'pre publish post' ?

css - 你如何找到百分比宽度的实际像素宽度

css - 在 Rails 的 Assets 管道中将图像编码为 css

html - 事件日历插件的 CSS

php - 如何阻止内容在固定标题下滚动?

html - 打印样式时如何去除顶部的空白

html - 在 css 中更改输入搜索表单的背景颜色