wordpress - Wordpress 在页脚中加载 CSS
问题描述
我怎样才能让这个函数将我的 CSS 加载到页脚中,而不是加载到谷歌页面速度的头部。我已经用谷歌搜索并尝试过,但我似乎无法让它工作。
function broa_script_enqueue() {
wp_enqueue_style('boostrapcss', get_template_directory_uri() . '/css/bootstrap.css', array(), '4.0.0', 'all');
wp_enqueue_style('customstyle', get_template_directory_uri() . '/css/style.css', array(), '1.0.0', 'all');
wp_enqueue_style('animatecss', get_template_directory_uri() . '/css/animate.css', array(), '1.0.0', 'all');
}
add_action( 'wp_enqueue_scripts', 'broa_script_enqueue' );
解决方案
你可以使用get_footer
钩子。将此代码放在活动主题的 function.php 中。
function prefix_add_footer_styles() {
wp_enqueue_style('boostrapcss', get_template_directory_uri() . '/css/bootstrap.css', array(), '4.0.0', 'all');
wp_enqueue_style('customstyle', get_template_directory_uri() . '/css/style.css', array(), '1.0.0', 'all');
wp_enqueue_style('animatecss', get_template_directory_uri() . '/css/animate.css', array(), '1.0.0', 'all');
};
add_action( 'get_footer', 'prefix_add_footer_styles' );
这个问题已经在这里描述了https://wordpress.stackexchange.com/questions/186065/how-to-load-css-in-the-footer
推荐阅读
- node.js - 使用 awilix 在函数中注入依赖项
- swift - 为什么自定义字体不应用于 Cocoa 应用程序
- spring-data-rest - Spring Data Rest findByIdIn
- android - 使用 Glide 将图片永久保存在缓存中
- python - 如何提高python语音识别的准确性?
- json - Slack APi 元数据 (slack_web.json) 更改
- javascript - jQuery UI 升级创建工具提示位置问题。jQuery 1.12.1 中的 .position() 有什么问题吗
- kotlin - SharedFlow 总是错过初始值
- reactjs - 在页面加载时使用 useEffect 挂钩播放音频
- jenkins - Groovy (Jenkins) 如何将文件导入/读取到 ${WORKSPACE}