繁体   English   中英

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

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

我是wordpress主题开发的新手。 现在我在订购一些CSS时遇到了一些问题。

我的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>

*编辑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,则会自动加载它。 现在,我想将style.css放置在其他CSS之下,并将normalize.css放在顶部以覆盖每个样式表。 我使用wp_enqueue_style并填充$ deps参数。 但这不会使任何事情发生。

有什么建议吗?

您能否在问题中尝试使用此代码而不是您的代码? 还搜索并删除任何其他wp_enqueue_style ,我认为默认的是在其他地方加载。 还要检查它是否在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');

您可能还需要像这样更新jQuery部分:

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

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

暂无
暂无

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

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