【问题标题】:Adding stylesheet in WordPress在 WordPress 中添加样式表
【发布时间】:2015-02-11 11:16:15
【问题描述】:

我想问一下为什么我的样式表没有显示在网页的页面源上。请看下面的代码,这是我的functions.php中的代码。

`function theme_styles() {

        wp_enqueue_style( 'main', get_template_directory_uri() . '/style.css' );
    }

    add_action( 'wp_enqueue_scripts', 'theme-styles' );`

我相信我已经正确输入了代码,但是每当我右键单击网页并查找源代码时,我的样式表都没有显示。顺便说一句,我正在使用 WebMatrix,我的 style.css 位于我目前正在处理的主题文件夹下。我是 WordPress 新手,我正在尝试创建自己的自定义主题。任何帮助将不胜感激。

非常感谢,

吉尔伯特·雅各布

【问题讨论】:

    标签: wordpress wordpress-theming


    【解决方案1】:

    试试这个:

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

    【讨论】:

      【解决方案2】:

      试试这个:

      function my_theme_load_resources() {
          $theme_uri = get_template_directory_uri();
          wp_register_style('style_css', $theme_uri.'/style.css', false, '0.1');
          wp_enqueue_style('style_css');
      }
      add_action('wp_enqueue_scripts', 'my_theme_load_resources');
      

      【讨论】:

        【解决方案3】:

        没关系,我注意到我的 theme_styles 使用了下划线,而我实际使用的是 theme-styles。谢谢!

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-07-23
          • 1970-01-01
          • 2015-10-24
          • 2017-09-28
          • 1970-01-01
          相关资源
          最近更新 更多