微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

css – wp_enqueue_style和rel而不是样式表?

我创建(或更好地尝试)用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()或其他内容).

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。