2016-06-13 59 views
0

默認情況下,WP排隊樣式表,因爲這:如何修改Wordpress樣式表排列的輸出或屬性?

<link rel="stylesheet" id="contact-form-7-css" href="http://www.wecodeart.com/wp-content/plugins/contact-form-7/includes/css/styles.css" type="text/css" media="all"> 

,我想一個過濾器或功能添加到這個鏈接另一個屬性,例如屬性=「樣式」 ......我可以做到這一點?

回答

0

是與str_replace函數可以

這裏是代碼

add_filter('style_loader_tag', 'style_loader_tag_function', 10, 2); 

function style_loader_tag_function($tag, $handle) { 



echo $tag; 

$tag = str_replace('rel="stylesheet"', 'rel="stylesheet/less"', $tag); 

if($handle=="contact-form-7") 
{ 

$tag = str_replace("rel='stylesheet'", "rel='stylesheet' property='stylesheet'", $tag); 
} 
    return $tag; 
} 
+0

非常感謝。 –

+0

總是歡迎:) –

0

試試這個:在當前激活的主題function.php

使用clean_url過濾器。

function add_my_custom_attributes($url) 
{ 
    $enqueue_attr = array (
     'http://www.wecodeart.com/wp-content/plugins/contact-form-7/includes/css/styles.css' //can also use site_url function  
    ); 
    if (in_array($url, $enqueue_attr)) 
    { // this will be optimized 
     return "$url' data-YOUR_NEW_ARRT='VALUE"; 
    }  
    return $url; 
} 
add_filter('clean_url', 'add_my_custom_attributes', 99, 1); 
+0

乾淨的網址被棄用... –

+0

@ BicanM.Valeriu過濾器仍在工作。請參閱https://developer.wordpress.org/reference/hooks/clean_url/ – vrajesh