【问题标题】:Wordpress functions.php not workingWordpress functions.php 不工作
【发布时间】:2015-02-05 11:07:40
【问题描述】:

尝试通过 functions.php 文件包含我的样式表,但样式无法显示...

function theme_styles () {

    wp_enqueue_style('normalize', get_template_directory_uri() . '/css/normalize.css' );
    wp_enqueue_style('grid', get_template_directory_uri() . '/css/grid.css' );
    wp_enqueue_style('style', get_template_directory_uri() . '/css/style.css' );
    wp_enqueue_style('google', '' );
    wp_enqueue_style('main', get_template_directory_uri() . '/style.css' );

}

我在主题文件夹中有 style.css 和一个带有 style.css 文件的 CSS 文件,但样式没有显示...

【问题讨论】:

  • 您是否在主题中的任何位置调用 theme_styles 函数?
  • 这将包含在哪里?
  • 我找到了我丢失的东西 - 感谢您的提醒 add_action('wp_enqueue_scripts', 'theme_styles');

标签: php css wordpress


【解决方案1】:

我遇到了类似的问题。过了一段时间,我意识到我忘了在head 标签的末尾添加wp_head() 钩子。

【讨论】:

    【解决方案2】:

    嘿 wp_enqueue_scripts 是在将样式表或脚本排入队列时使用的正确挂钩

    用于将样式表排入队列

    function theme_styles () {
    
        wp_enqueue_style('normalize', get_template_directory_uri() . '/css/normalize.css' );
        wp_enqueue_style('grid', get_template_directory_uri() . '/css/grid.css' );
        wp_enqueue_style('style', get_template_directory_uri() . '/css/style.css' );
        wp_enqueue_style('google', '' );
        wp_enqueue_style('main', get_template_directory_uri() . '/style.css' );
    
    }
    add_action( 'wp_enqueue_scripts', 'theme_styles' );
    

    肯定会很好用的

    【讨论】:

      【解决方案3】:

      尝试使用bloginfo('stylesheet_directory') 而不是get_template_directory_uri()

      【讨论】:

      • 没有改变任何东西,我觉得我在这里遗漏了一些东西,但不太确定是什么......
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-19
      • 2016-12-30
      • 1970-01-01
      相关资源
      最近更新 更多