WordPress function wp_enqueue_style is missing rel parameter

I am trying to build wordpress plugin with polymer at admin side. Polymer use link element to import the library. However wp function “wp_enqueue_style” is missing setting up rel attribute. This is from the official doc (link):

wp_enqueue_style( $handle, $src, $deps, $ver, $media );

Read More

There is a function named “wp_style_add_data” but I tried to set rel attribute in this way without any luck:

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

Here is example of importing polymer:

<link rel="import" href="bower_components/polymer/polymer.html">

I was developing wp plugins long time ago, so I would appreciate your help to find a best workaround to this limitation.

Related posts

1 comment

  1. You can use the style_loader_tag filter:

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

    Change polymer-handle with the actual handle.

Comments are closed.