mercredi 28 janvier 2015

Add attribute to link tag that's generated through wp_register_style?


My original question was answered here: Google Fonts giving: No 'Access-Control-Allow-Origin' header is present on the requested resource.


Is there a way to add the data-noprefix attribute to my Google Fonts link tag?


My functions.php looks like this:



wp_register_script( 'prefixfree', get_template_directory_uri().'/js/prefixfree.min.js', array( 'jquery' ) );
wp_enqueue_script( 'prefixfree' );

wp_register_style( 'google-fonts', 'http://ift.tt/1H0ZlXb', '', '', 'all' );
wp_enqueue_style( 'google-fonts' );


Answer, with the help of Birgire:



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

function add_noprefix_attribute($link, $handle) {
if( $handle === 'google-fonts' ) {
$link = str_replace( '/>', 'data-noprefix />', $link );
}
return $link;
}




Aucun commentaire:

Enregistrer un commentaire