Bican M. Valeriu
Bican M. Valeriu

Reputation: 328

How to modify output or attributes of Wordpress Stylesheets enqueue?

By default WP enqueue stylesheets as this:

<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">

And i want a filter or function to add to this link another attribute, for example property="stylesheet"...can i do that ?

Upvotes: 0

Views: 721

Answers (2)

vrajesh
vrajesh

Reputation: 2942

Try this :

Use clean_url filter in function.php of your current activated theme.

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

Upvotes: 0

Hiral Suvagya
Hiral Suvagya

Reputation: 601

yes with str_replace it is possible

here is code

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

Upvotes: 1

Related Questions