css - Enqueue Style Function Not Loading

I've been reading Wordpress Theme Developer Handbook to learn how things work and try to practice according to what

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' );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745308845a4621876.html

相关推荐

  • css - Enqueue Style Function Not Loading

    I've been reading Wordpress Theme Developer Handbook to learn how things work and try to practice according to what

    5小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信