簡體   English   中英

Wordpress函數wp_enqueue_style缺少rel參數

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM