[英]Wordpress - wp_enqueue_script / wp_enqueue_style doesn't work
[英]Wordpress function wp_enqueue_style is missing rel parameter
我正在嘗試在管理端用聚合物來構建wordpress插件。 聚合物使用鏈接元素導入庫。 但是,wp函數“ wp_enqueue_style”缺少設置rel屬性的功能。 這是來自官方文檔( 鏈接 ):
wp_enqueue_style($ handle,$ src,$ deps,$ ver,$ media);
有一個名為“ wp_style_add_data”的函數,但我試圖以此方式設置rel屬性,但沒有任何運氣:
wp_enqueue_style('polymer_html', plugin_dir_url(__FILE__).'../js/bower_components/polymer/polymer.html', array(), '1.0', 'all');
wp_style_add_data('polymer_html', 'rel', 'import'); //this way
wp_style_add_data('polymer_html', 'import', true); //and also this way
這是導入聚合物的示例:
<link rel="import" href="bower_components/polymer/polymer.html">
我很久以前就在開發wp插件,因此,感謝您的幫助,以找到解決此限制的最佳方法。
您可以使用style_loader_tag
過濾器:
add_filter( 'style_loader_tag', function( $html, $handle, $href ) {
if( 'polymer-handle' === $handle )
$html = str_replace('href=', 'rel="import" href=', $html);
return $html;
}, 10, 3 );
用實際的手柄更改polymer-handle
手柄。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.