minified css is getting overwritten by bootstrap c

2019-09-18 02:57发布

问题:

i'm using a plugin called "w3 total cache" on wordpress that minifies my style.css (which is located in my theme folder). the problem is that in function.php i enqueued the boostrap cdn and style.css correctly like this:

   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');     

BUT, whenever my page loads the style.css gets minified right after the head tags and bootstrap stays below overwriting all my rules...

this is the website i'm working on: http://bootstraptest.co.nf

if you move the first stylesheet right after bootstrap you can see the button working and the header getting placed correctly.

回答1:

In header.php add <!-- W3TC-include-css --> code after wp_head()

Like this:

    <?php wp_head(); ?>
    <!-- W3TC-include-css -->
</head>

This will cause the mined w3tc file to appear after your bootstrap call