Wp_enqueue_style and rel, except for the stylesheet?

I am creating (or better trying) to create my first WordPress theme using Less.

What I am doing is using a script like this in my functions.php

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

and the result is as follows:

 <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' /> 

The question is, can I somehow change rel = "stylesheet" when I use the wp_register_style () function?

+7
source share
2 answers

While none of the functions allow you to pass this value, you have access to the tag before rendering it using the style_loader_tag filter. If you do something like this ...

 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; } 

... you should be able to replace the rel attribute with whatever you want. Keep in mind that this filter will go through the whole tag as html, so you will need to do preg_replace () or something similar to replace the value with what you want. In addition, this filter will run every time you insert a stylesheet, so make sure you check that you have the correct one (with preg_match () or something else) before changing the rel attribute.

+7
source

I know this is old q, but it helped me figure it out. borrowing from a brand name answers here the full function that I used:

 function childtheme_scripts() { wp_enqueue_style('less',get_stylesheet_directory_uri() .'/style.less'); add_filter('style_loader_tag', 'my_style_loader_tag_function'); wp_enqueue_script('less',get_stylesheet_directory_uri() .'/jscripts/less-1.3.0.min.js', false,'1.3.0'); } add_action('wp_enqueue_scripts','childtheme_scripts', 1); function my_style_loader_tag_function($tag){ //do stuff here to find and replace the rel attribute return preg_replace("/='stylesheet' id='less-css'/", "='stylesheet/less' id='less-css'", $tag); } 
+3
source

All Articles