最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

I can't in any way include css in my theme using functions.php

programmeradmin5浏览0评论

I can't in any way include css in my theme using functions.php

I tried to include css using the link tag, but it only loads it on the first page, then when I go to open other pages (for example the example page) I don't load any style, how can I do it?

this is the code:

function theme_styles()
{
    wp_enqueue_style( 'style', get_template_directory_uri() . '/style.css' );
  wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css' );
  wp_enqueue_style( 'font', get_template_directory_uri() . '/css/font-awesome.min.css' );
}
add_action('wp_enqueue_scripts', 'theme_styles');

I can't in any way include css in my theme using functions.php

I tried to include css using the link tag, but it only loads it on the first page, then when I go to open other pages (for example the example page) I don't load any style, how can I do it?

this is the code:

function theme_styles()
{
    wp_enqueue_style( 'style', get_template_directory_uri() . '/style.css' );
  wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css' );
  wp_enqueue_style( 'font', get_template_directory_uri() . '/css/font-awesome.min.css' );
}
add_action('wp_enqueue_scripts', 'theme_styles');
Share Improve this question edited Jan 9, 2020 at 17:48 Pat J 12.5k2 gold badges28 silver badges36 bronze badges asked Jan 9, 2020 at 15:31 Andrea SalvatoreAndrea Salvatore 11 bronze badge 3
  • Does the tag not appear on the other pages? Which file is this code located in? Are there any errors or warnings in your browser dev tools console? Is this a child theme? – Tom J Nowell Commented Jan 9, 2020 at 17:53
  • 2 Is this a child theme? If so, you probably want to use get_stylesheet_directory_uri() to point to child theme stylesheets. get_template_directory_uri() pulls from the parent theme. – WebElaine Commented Jan 9, 2020 at 17:55
  • Does your theme have a header.php file with the wp_head() function inside the <head> tags? – Jacob Peattie Commented Jan 10, 2020 at 0:04
Add a comment  | 

1 Answer 1

Reset to default 0

In your first enqueue type get_stylesheet_directory_uri() instead of get_template_directory_uri For stylesheet its functions.php requires get_stylesheet_directory_uri()

发布评论

评论列表(0)

  1. 暂无评论