php - WordPress “wp_register_style 调用不正确”?
问题描述
我有个问题。当我想将此代码放在我的第一个 Wordpress 模板中时,不起作用。我有一个用于引导程序的库,还有一个用于我的风格的库。为什么?下面是我的代码。谢谢 :D
function load_stylesheets() // funtion name
{
wp_register_style('style', get_template_directory_uri() . 'style.css', array(), false, 'all');//style.css
wp_enqueue_style('style');
wp_register_style('bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css', array(), false, 'all');// this is for bootstrap.
wp_enqueue_style('bootstrap');
}
// 添加动作
add_action('wp_enqueue_scripts', 'load_stylesheets');
//我的首页.php
<div class="container">
<div class="row">
<div class="col">
Left
</div>
<div class="col">
Right
</div>
</div>
//style.css
body{
background-color: red;
}
解决方案
也许我做错了,但我还不能发表评论,但是我想说尝试从 the 中取出可选参数,wp_register_style
然后让它:
wp_register_style('my-style', get_template_directory_uri() . 'style.css');
wp_enqueue_style('my-style');
您可以在此处查看可选参数:https ://developer.wordpress.org/reference/functions/wp_register_style/
不要忘记将 enqueue 的名称更改为您的样式的名称...如果您更改了样式的名称
另外,只需确保因为 Bootstrap 样式表位于 css 目录中,style.css 是在同一目录中还是 style.css 在您的主模板目录中?如果它在主模板目录中,那么它很好,但如果它在 css 目录中,您需要确保添加/css/style.css
到您的wp_register_style
推荐阅读
- ajax - 使用ajax关闭模式后无法重新打开模式
- python - pandas resample dropna 不适用于所有列
- cesium - 如何获得用铯渲染的gltf纹理的状态
- javascript - 添加后缀跟随用户输入材料ui TextField
- reactjs - 如何从 React PWA 调用 HTTP 请求?
- css - 菜单重叠
- c# - 使用 C# Visual Studio 从 URL 显示 RDLC 中的图像
- scala - Scala 文件行映射
- python - 使用 Cloud Functions 在 Google Cloud Platform 中设置环境变量
- excel - 将“工作日”添加到 Excel 公式中的“if”语句中