简体   繁体   English

如何使用wordpress在“ wp_enqueue_style”中包含多个样式表?

[英]How to include multiple stylesheets with “wp_enqueue_style” using wordpress?

For my website, I am trying to include my own stylesheet for icons other than font-awesome. 对于我的网站,我正在尝试为除真棒字体之外的其他图标添加自己的样式表。 However, no matter what I do with "wp_enqueue_style", I can only end up using one of the stylesheets (either mine or font-awesome) but not both. 但是,无论我用“ wp_enqueue_style”做什么,我最终只能使用其中一个样式表(我的样式表或超赞的字体),但不能同时使用两者。 Only one would be working. 只有一个会工作。 I was wondering what I am doing incorrectly with my coding here: 我想知道我在这里的编码做错了什么:

wp_enqueue_style( 'vantage-fontawesome', get_template_directory_uri().'/fontawesome/css/font-awesome.css', array(), '3.2.1' ); wp_enqueue_style( 'Mystyle', get_template_directory_uri().'/fontawesome/css/Mystyle.css', array());

What can I do so that both 'font-awesome.css' and 'mystyle.css' can be used? 我该怎么做才能同时使用“ font-awesome.css”和“ mystyle.css”? Thanks 谢谢

You should wrap wp_enqueue_style() in a function and hook that function to wp_enqueue_scripts . 您应该将wp_enqueue_style()包装在一个函数中,然后将该函数挂接到wp_enqueue_scripts For example: 例如:

function theme_name_scripts() {
    wp_enqueue_style( 'style-name', get_stylesheet_uri() );

    // Enqueue more style sheets here.
}

add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );

Ref: http://codex.wordpress.org/Function_Reference/wp_enqueue_style 参考: http : //codex.wordpress.org/Function_Reference/wp_enqueue_style

You're code should look like this. 您的代码应如下所示。

function my_scripts() {

// Add Mystyle 
wp_enqueue_style( 'Mystyle', get_template_directory_uri().'/fontawesome/css/Mystyle.css',array());

// Add Font Awesome
 wp_enqueue_style( 'vantage-fontawesome', get_template_directory_uri().'/fontawesome/css/font-awesome.css', array(), '3.2.1' );
 }
//Push to wordpress all files
add_action( 'wp_enqueue_scripts', 'my_scripts' );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM