Ordering Wordpress Stylesheets?

前端 未结 4 1631
北恋
北恋 2020-12-17 10:57

I have a wordpress theme with a stylesheet that needs to be loaded last, since plugin css are interfering with my theme. I was wondering if there was some type of function I

4条回答
  •  無奈伤痛
    2020-12-17 11:41

    You can always use !important to override other rules, but I recommend to also be sure that the plugin stylesheets are being inserted properly using the following method. By adding the priority number you can render them at a later time.

    Be sure your stylesheets are loading before all your scripts inside the tag of your header.

    You always need to load stylesheets before scripts and wordpress takes care of that if you use wp_enqueue_style and wp_enqueue_script

    For example in your functions.php you should use

    add_action('wp_enqueue_scripts', function(){
        wp_enqueue_style('main-style','http://yoursite.com/styles/main.css');
    }, 99);
    

    Wordpress then will place main.css in your header and giving a 99 priority means it will add it later than the rest (by default the priority of this function it's 10)

    Be sure you got wp_head() in your header file.

    Regards

提交回复
热议问题