简体   繁体   English

WordPress:wp_enqueue_style不起作用

[英]Wordpress: wp_enqueue_style not working

I see that others have had problems with this function in more particular cases, but I really am just having trouble getting it to work at all. 我看到其他人在更特殊的情况下对此功能有问题,但是我真的很难使它完全起作用。

I have this in my functions.php : 我在我的functions.php有这个:

function load_styles() {
    wp_register_style( 'style', get_stylesheet_uri() );
    wp_enqueue_style( 'style' );
}
add_action( 'wp_enqueue_scripts', 'load_styles' );

This has no effect on the styling of my site. 这对我的网站样式没有影响。 It works if I put this in header.php instead: 如果将它放在header.php它将起作用:

<link rel="stylesheet" href="<?php echo get_stylesheet_uri(); ?>" />

I would just go with the latter, then (even though I know it's not technically proper), but for some reason my media queries aren't working that way so I thought I would try to enqueue the styles properly. 然后,我会选择后者(即使我知道这在技术上不合适),但是由于某种原因,我的媒体查询无法正常工作,因此我认为我会尝试适当地排入样式。 I'm totally at a loss here; 我在这里完全不知所措; any suggestions greatly appreciated. 任何建议,不胜感激。

You should just be able to enqueue your theme's style without registering it first. 您应该能够无需先注册就可以使主题的样式入队。

wp_enqueue_style('style', get_stylesheet_uri(), []);

If that still doesn't work, check that your header.php includes wp_head(); 如果仍然wp_head(); ,请检查header.php包含wp_head(); as that outputs the enqueued styles. 因为这会输出排队的样式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM