Using conditional checks in the functions.php file
-
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 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘Using conditional checks in the functions.php file’ is closed to new replies.