简体   繁体   English

将style.css放在wordpress中的其他CSS下方

[英]Put style.css below other css in wordpress

I'am new in wordpress theme development. 我是wordpress主题开发的新手。 Now i have some problem with ordering some css. 现在我在订购一些CSS时遇到了一些问题。

My wordpress generate head tags like this 我的wordpress生成这样的head标签

<head>
   ...
   <link rel="stylesheet" type="text/css" href="http://localhost/wordpress/wp-content/themes/muarif/style.css">
   ...
   <link rel="stylesheet" id="normalize-css" href="http://localhost/wordpress/wp-content/themes/muarif/inc/css/normalize.css?ver=4.1.1" type="text/css" media="all">
   <link rel="stylesheet" id="bootstrap-css" href="http://localhost/wordpress/wp-content/themes/muarif/inc/css/bootstrap.css?ver=4.1.1" type="text/css" media="all">
   ...
</head>

*edit for wp_enqueue_style *编辑wp_enqueue_style

 function site_script(){
    wp_enqueue_style('normalize',get_template_directory_uri().'/inc/css/normalize.css');
    wp_enqueue_style('bootstrap',get_template_directory_uri().'/inc/css/bootstrap.css');

    //jquery script
    wp_register_script('jquery',get_template_directory_uri().'/inc/js/jquery.js');
    wp_enqueue_script('jquery');

    //angular script
    wp_register_script('angular',get_template_directory_uri().'/inc/js/angular.js');
    wp_enqueue_script('angular');

    //bootstrap script
    wp_register_script('bootstrap',get_template_directory_uri().'/inc/js/bootstrap.min.js',array('jquery'));
    wp_enqueue_script('bootstrap');

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

Style.css is load automatically if it exist in theme. 如果主题中存在Style.css,则会自动加载它。 Now i want to put style.css below than other css and put normalize.css on top for overriding on each stylesheet. 现在,我想将style.css放置在其他CSS之下,并将normalize.css放在顶部以覆盖每个样式表。 I use wp_enqueue_style and fill $deps parameter. 我使用wp_enqueue_style并填充$ deps参数。 But it dont make anything happen. 但这不会使任何事情发生。

Any advice? 有什么建议吗?

Can you try this code instead of yours in the question. 您能否在问题中尝试使用此代码而不是您的代码? Also search and remove any other wp_enqueue_style , I think the default one is being loading somewhere else before. 还搜索并删除任何其他wp_enqueue_style ,我认为默认的是在其他地方加载。 Also check if it's hardcoded in header.php 还要检查它是否在header.php硬编码

function site_script(){
    wp_enqueue_style('normalize',get_template_directory_uri().'/inc/css/normalize.css');
    wp_enqueue_style('bootstrap',get_template_directory_uri().'/inc/css/bootstrap.css');
    wp_enqueue_style('theme_name',get_template_directory_uri().'/style.css');

    //jquery script
    wp_register_script('jquery',get_template_directory_uri().'/inc/js/jquery.js');
    wp_enqueue_script('jquery');

    //angular script
    wp_register_script('angular',get_template_directory_uri().'/inc/js/angular.js');
    wp_enqueue_script('angular');

    //bootstrap script
    wp_register_script('bootstrap',get_template_directory_uri().'/inc/js/bootstrap.min.js',array('jquery'));
    wp_enqueue_script('bootstrap');

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

You might also need to update the jQuery part like this: 您可能还需要像这样更新jQuery部分:

if (!is_admin()) {
    wp_deregister_script('jquery');
    wp_register_script('jquery',get_template_directory_uri().'/inc/js/jquery.js');
    wp_enqueue_script('jquery');
}

FYI: http://codex.wordpress.org/Function_Reference/wp_register_script 仅供参考: http : //codex.wordpress.org/Function_Reference/wp_register_script

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

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