【问题标题】:How to add a style sheet after all the other added style sheets in wordpress?如何在 wordpress 中所有其他添加的样式表之后添加样式表?
【发布时间】:2018-03-03 13:06:38
【问题描述】:

我从我网站上安装的主题创建了一个子主题。我创建了一个自定义页面并使用

向其中添加了样式表

wp_enqueue_style( 'page-template', get_template_directory_uri() . '/css/custom-page-style.css')

但它是在其他样式表的顶部添加的,也就是说我添加的样式会被其他样式表覆盖。

如何在其他样式表的末尾、</head> 之前制作此样式表,以便覆盖其他样式表?

【问题讨论】:

    标签: wordpress css


    【解决方案1】:

    将此添加到您的子主题的function.php中

     example_enqueue_styles() {
    
    // enqueue parent styles
    wp_enqueue_style('parent-theme', get_template_directory_uri() .'/style.css');
    
    // enqueue child styles
    wp_enqueue_style('child-theme', get_stylesheet_directory_uri() ./css/custom-page-style.css', array('parent-theme'));
    }
    add_action('wp_enqueue_scripts', 'example_enqueue_styles');
    

    【讨论】:

      【解决方案2】:

      wp_enqueue_style的完整API是:

      wp_enqueue_style( $handle, $src, $deps, $ver, $media );
      

      $deps 代表依赖,默认是空的array(),你可以传入一个依赖列表,你的custom-page-style.css在注入到html页面之前需要它。

      例如:

      wp_enqueue_style( 'child-theme', get_stylesheet_directory_uri() . '/css/custom-page-style.css', array('jQuery', 'bootstrap'));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-20
        • 1970-01-01
        相关资源
        最近更新 更多