我想在 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
并将 path 和 filename.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/