Wordpress load CSS In footer

人盡茶涼 提交于 2020-04-16 04:02:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!