【问题标题】:wp_enqueue_style not working as expectedwp_enqueue_style 未按预期工作
【发布时间】:2018-12-17 10:55:51
【问题描述】:

所以我正在尝试将我的静态网站迁移到 WordPress 网站,但无法正确加载样式和脚本。

这是我的functions.php

<?php
function my_styles() {
  wp_enqueue_style( 'style', get_template_directory_uri() . 'css/style.css', false, '1.0', 'all');
}

add_action ('wp_enqueue_scripts', 'my_styles');
?>

我的 style.css 位于名为 css 的文件夹中,该文件夹位于主题文件夹本身中。任何人都知道为什么这不会按预期加载样式表?

【问题讨论】:

    标签: wordpress styles


    【解决方案1】:

    你所缺少的只是 css 之前的斜线。祝你好运!

    wp_enqueue_style( 'style', get_template_directory_uri() . '/css/style.css', false, '1.0', 'all');
    

    【讨论】:

      【解决方案2】:

      试试这个代码

      <?php
      add_action( 'wp_enqueue_scripts', 'thene_styles', PHP_INT_MAX);
      
      function theme_styles() {
          wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array('parent-style') );
      }
      ?>
      

      【讨论】:

        猜你喜欢
        • 2021-06-04
        • 2022-01-24
        • 2015-05-11
        • 2020-05-15
        • 2014-10-31
        • 2018-02-12
        • 2014-01-20
        • 2015-01-13
        • 2013-08-01
        相关资源
        最近更新 更多