2015-01-26 62 views
2

我原來的回答是:Google Fonts giving: No 'Access-Control-Allow-Origin' header is present on the requested resource.將屬性添加到通過wp_register_style生成的鏈接標記?

有沒有辦法將data-noprefix屬性添加到我的Google Fonts鏈接標記中?

我的functions.php看起來是這樣的:

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

wp_register_style('google-fonts', 'http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,300italic,400,400italic,600,600italic,700,700italic', '', '', 'all'); 
wp_enqueue_style('google-fonts'); 

回答

1

這爲我工作:

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; 
} 
相關問題