gpt4 book ai didi

css - wp_enqueue_style 和 rel 除了样式表?

转载 作者:技术小花猫 更新时间:2023-10-29 10:56:35 26 4
gpt4 key购买 nike

我创建(或更好地尝试)使用 Less 创建我的第一个 WordPress 主题。

我所做的是在我的 functions.php 中使用这样的脚本

wp_register_style('screen_css', get_bloginfo('template_url') . '/css/screen.less', array(), false, 'screen');
wp_enqueue_style('screen_css');

结果是:

<link rel='stylesheet' id='stigma_screen-css'  href='http://www.stigmahost.dch/wp-content/themes/stigmahost/css/screen.less?ver=1.0' type='text/css' media='screen' />

问题是,我可以在使用 wp_register_style() 函数时以某种方式更改 rel="stylesheet"吗?

最佳答案

虽然这两个函数都不会让您传递该值,但您可以在使用 style_loader_tag 过滤器呈现标签之前访问该标签。如果你做这样的事情......

add_filter('style_loader_tag', 'my_style_loader_tag_function');

function my_style_loader_tag_function($tag){
//do stuff here to find and replace the rel attribute

return $tag;
}

...您应该能够用您想要的任何内容替换 rel 属性。请记住,此过滤器会将整个标记作为 html 传递,因此您必须执行 preg_replace() 或类似操作以将值替换为您想要的值。此外,每次您对样式表进行排队时都会运行此过滤器,因此请确保在更改 rel 属性之前测试您是否拥有正确的样式表(使用 preg_match() 或其他东西)。

关于css - wp_enqueue_style 和 rel 除了样式表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8082236/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com