问题
How can I get this function to load my css in the footer and not in the head for google page speed. I've googled it and tried but I cant seem to get it to work.
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' );
回答1:
You can use get_footer
hook. Put this code in your active theme's 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' );
This question is already described here https://wordpress.stackexchange.com/questions/186065/how-to-load-css-in-the-footer
回答2:
change add_action( 'wp_enqueue_scripts', 'broa_script_enqueue' ); to add_action( 'wp_footer', 'broa_script_enqueue' );
来源:https://stackoverflow.com/questions/52057380/wordpress-load-css-in-footer