在我看来,您也可以使用style\\u loader\\u标记,请参阅我的另一个答案,以了解对这两者的更详细了解style_loader_tag 和script_loader_tag API:
How to add crossorigin and integrity to wp_register_style? (Font Awesome 5)
style\\u loader\\u标记是官方WordPress API,请参阅文档:https://developer.wordpress.org/reference/hooks/style_loader_tag/
apply_filters( \'style_loader_tag\', $html, $handle, $href, $media )
过滤排队样式的HTML链接标记。
First, enqueue your stylesheets
function add_styles() {
// Example loading external stylesheet, could be used in both a theme and/or plugin
wp_enqueue_style( \'font-awesome-5\', \'https://use.fontawesome.com/releases/v5.5.0/css/all.css\', array(), null );
// Example theme
wp_enqueue_style( \'font-awesome-5\', get_theme_file_uri( \'/assets/css/fontawesome.min.css\' ), array(), null );
// Example plugin
wp_enqueue_style( \'font-awesome-5\', plugins_url( \'/assets/css/fontawesome.min.css\', __FILE__ ), array(), null );
};
add_action( \'wp_enqueue_scripts\', \'add_styles\' );
Second, use style_loader_tag然后使用style\\u loader\\u标记将标题添加到特定样式表中。
function add_stylesheet_attributes( $html, $handle ) {
if ( \'font-awesome-5\' === $handle ) {
return str_replace( "rel=\'stylesheet\'", "rel=\'stylesheet\' title=\'something\'", $html );
}
return $html;
}
add_filter( \'style_loader_tag\', \'add_stylesheet_attributes\', 10, 2 );