2

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' ); 

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

3 Comments

When I do ( 'wp_enqueue_scripts', 'broa_script_enqueue' ); to add_action( 'wp_footer', 'broa_script_enqueue' ); it wont load the css.
function prefix_add_footer_styles() But when I do that it wont load my styles for any reason. I tried that one before posting here. I get no php errors or so. But the style wont load.
With WordPress 6.2, the hook "wp_footer" worked but "get_footer" did not <shrug>. Regardless, your answer helped me so I voted it up.
3

change add_action( 'wp_enqueue_scripts', 'broa_script_enqueue' ); to add_action( 'wp_footer', 'broa_script_enqueue' );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.