Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

gilgimech on "Using conditional checks in the functions.php file"

$
0
0

You can't use the conditional checks in the functions.php file, because the functions.php file loads before the page loads, so the conditional functions have nothing to check against.

Like

function load_js() {
    if(is_home()){
        wp_register_script('main.min.js', THEME_URL . 'js/main.min.js', false, '1.0', true);
        wp_enqueue_script('main.min.js');
    }
}
add_action('init', 'load_js');

Just won't work. Correct?

I don't remember where I stumbled across this, but I discovered a work around.

if you add

<?php do_action('init'); ?>

after wp_head() the conditional checks in the functions.php work.

I don't now why this works, but it does.

Does anyone have any idea why this does work>


Viewing all articles
Browse latest Browse all 8245

Trending Articles