Giulio Bambini
Giulio Bambini

Reputation: 4755

How to load css in the footer in function.php with wordpress theme

I was trying to move the load of my style.css in the footer of my wordpress theme. I have already done something similar with 2 js files and it works fine, they load in the footer:

function my_init() {
    if (!is_admin()) {
        wp_deregister_script('jquery');
        wp_register_script('jquery', 'http://www.studionews24.com/wp-content/themes/network/js/jquery.min.js', false, '1.3.2', true);
        wp_enqueue_script('jquery');

        // load a JS file from my theme: js/theme.js
        wp_enqueue_script('my_script', 'http://www.studionews24.com/wp-content/themes/network/js/menu-resp.js', array('jquery'), '1.0', true);
    }
}
add_action('init', 'my_init');

Now i was trying to move in the footer also the style.css, and keep only some inline css rules in the <head> tag. I have tried wp_enqueue_style but it seems doesn't work well for me.

Someone could help me for find a smart solution?

Upvotes: 1

Views: 4396

Answers (2)

Ashish Patel
Ashish Patel

Reputation: 3614

replace

add_action('init', 'my_init');

with

add_action('wp_footer', 'my_init', 100);

Upvotes: 1

Ari
Ari

Reputation: 4969

Try this:

add_action('wp_footer', 'my_init');

or since you have add parameter true in your script callback function:

add_action('wp_enqueue_scripts', 'my_init');

You may go here http://wordpress.stackexchange.com if you need help around wordpress programming.

Upvotes: 3

Related Questions