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

css - Enqueue Style Function Not Loading

programmeradmin1浏览0评论

I've been reading Wordpress Theme Developer Handbook to learn how things work and try to practice according to what's written in there.

I've created my index.php, style.css, function.php and header and footer files. According to the Including CSS & JavaScript Part . it says that other than directly use the link tag, i need to create a functions.php and in to that file i need to add wp_enqueue_style( 'style', get_stylesheet_uri() ); function with these parameters.

I am adding this line of code to my functions.php but I can't see the file when I look at the source of the page.

I also tried to add this function to my header.php instead of functions.php , it doesn't seem to work.

I've been reading Wordpress Theme Developer Handbook to learn how things work and try to practice according to what's written in there.

I've created my index.php, style.css, function.php and header and footer files. According to the Including CSS & JavaScript Part . it says that other than directly use the link tag, i need to create a functions.php and in to that file i need to add wp_enqueue_style( 'style', get_stylesheet_uri() ); function with these parameters.

I am adding this line of code to my functions.php but I can't see the file when I look at the source of the page.

I also tried to add this function to my header.php instead of functions.php , it doesn't seem to work.

Share Improve this question edited Jul 21, 2019 at 0:25 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Jul 20, 2019 at 22:29 NoobDevNoobDev 132 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Your call to wp_enqueue_style() looks good and functions.php is the right place, but your code should be wrapped inside a function attached to the wp_enqueue_scripts hook. See the Combining Enqueue Functions section of the page you referenced for a full example. Generally speaking, any code you run in WordPress should be run on some hook or filter. Otherwise the code will be run as soon as the code is read which is usually not the correct time.

function mytheme_add_theme_scripts() {
  wp_enqueue_style( 'style', get_stylesheet_uri() );
}
add_action( 'wp_enqueue_scripts', 'mytheme_add_theme_scripts' );
发布评论

评论列表(0)

  1. 暂无评论