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

前端之家收集整理的这篇文章主要介绍了css – wp_enqueue_style和rel而不是样式表?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我创建(或更好地尝试)用Less创建我的第一个wordpress主题.

我所做的是在我的functions.PHP中使用这样的脚本@H_403_3@

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

结果是:@H_403_3@

<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”吗?@H_403_3@

解决方法

虽然这两个函数都不允许您传递该值,但在使用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()或其他内容).@H_403_3@

原文链接:https://www.f2er.com/css/215797.html

猜你在找的CSS相关文章