首页 > 解决方案 > 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' ); 

标签: wordpressperformancefooter

解决方案


你可以使用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


推荐阅读