简体   繁体   中英

style.css gets included before bootstrap

i'm trying to overwrite bootstrap with my style.css (placed by default in my wordpress theme folder). so this is the code i have in my functions.php to enqueue the bootstrap cdn and my css:

function bootstrap() { 
wp_enqueue_style( 'bootstrap-css', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css' ); 
wp_enqueue_script( 'bootstrap-js', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js',  array('jquery') );

}
add_action('wp_enqueue_scripts', 'bootstrap');

function maincss() {
wp_enqueue_style( 'maincss', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'maincss');

and this is what my head looks like in my google's inspector:

<link rel="stylesheet" id="maincss-css" href="http://bootstraptest.co.nf/wp-content/themes/HipsterTheme/style.css?ver=1.0.0" type="text/css" media="screen">

<link rel="stylesheet" id="bootstrap-css-css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css?ver=4.2.3" type="text/css" media="all">

i'm pretty new with wordpress so be nice to me :P

根据文档wp_enqueue_style ,应使用$ deps参数声明maincss的依赖关系,如下所示:

wp_enqueue_style( 'maincss', get_template_directory_uri() . '/style.css',array('bootstrap-css') );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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