【问题标题】:How to add a new stylesheet to my wordpress如何将新样式表添加到我的 wordpress
【发布时间】:2013-12-25 22:29:39
【问题描述】:

我一直在尝试向我的模板添加新样式表,但没有成功。这是我第一次创建 wordpress 模板。我正在使用underscore,这就是我在 functions.php 中所拥有的:

style.css 是模板启动器附带的样式表。

wp_enqueue_style( 'name-style', get_stylesheet_uri() );

我只想添加 foundation-icons.cssfoundation.min.css >custom.css。有什么帮助吗?谢谢。

【问题讨论】:

    标签: css wordpress stylesheet


    【解决方案1】:

    这就是我在我所有的模板

    中的做法
    /* Enqueue Scripts
    -----------------------------------------------------------------*/
    add_action( 'wp_enqueue_scripts', 'template_enqueue_scripts' );
    function template_enqueue_scripts() {
        wp_register_style('Sub-CSS', get_template_directory_uri() .'sub-style.css');
        wp_enqueue_style( 'Sub-CSS'); 
    }
    

    据我所知,这是最好的方法,就像我说的,我总是这样做。它完美无缺,我从来没有遇到过这样的问题。

    编辑

    您会注意到没有其他人使用 wp_register_style,而 wp_register_style 是为实际排队设置样式的最安全方法。

    确保将 wp_register_style 和 wp_enqueue_style 包装在一个函数中。

    【讨论】:

      【解决方案2】:

      试试这个代码:

      <?php
      
          add_action( 'wp_enqueue_scripts', 'safely_add_stylesheet' );
      
          /**
           * Add stylesheet to the page
           */
          function safely_add_stylesheet() {
              wp_enqueue_style( 'prefix-style', plugins_url('style.css', __FILE__) );
          }
      ?>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-10-27
        • 1970-01-01
        • 2012-05-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多