css - wp_enqueue_style 和 rel 除了样式表?

标签 css wordpress wordpress-theming less

我创建(或更好地尝试)使用 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/

相关文章:

html - 基于边界图像溢出百分比的网格系统

html - Bootstrap : Thumbnail is creating horizontal overflow

html - 为什么 wordpress 生成随机 <br> 并错开我的图像

javascript - WordPress 中的 masonry

javascript - 可以更有效地重写这个 jQueryJjavaScript 片段吗?

css - 隐藏移动内容

wordpress - 更改添加到购物车按钮与 woocommerce 中的产品查询表格

php - 反序列化wordpress数据库来查询数据

javascript - 页眉不透明度不适用于页面

php - 在 wordpress 中检测主页有哪些不同的方法?