You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WordPress主题HTML缺失style.css文件名问题求助

解决WordPress主题未加载style.css的问题

问题出在你调用的get_stylesheet_directory_uri()函数上——它返回的只是主题目录的URI,不会自动指向style.css文件,所以输出的href才会停在主题目录层级,没包含样式文件路径。

你可以通过以下两种方式修复:

  • 方法一:使用专门获取主题style.css的函数get_stylesheet_uri(),修改后的代码如下:
function my_theme_scripts() {
    wp_enqueue_style( 'style-own', get_stylesheet_uri() );
}
add_action( 'wp_enqueue_scripts', 'my_theme_scripts' );
  • 方法二:手动给主题目录URI拼接/style.css路径,代码如下:
function my_theme_scripts() {
    wp_enqueue_style( 'style-own', get_stylesheet_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'my_theme_scripts' );

修改后,输出的link标签会自动带上style.css路径,变成类似:

这样就能正常加载主题的样式文件了。

内容的提问来源于stack exchange,提问作者user10162013

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 20:37:31