This code is working in my functions.php and it’s loaded properly:
add_action('wp_enqueue_scripts', 'js_custom', 50);
function js_custom() {
wp_register_script( 'js_custom', get_template_directory_uri() . '/js/custom.js', false, null);
wp_enqueue_script( 'js_custom' );
}
However, this is not working and not loaded:
if ( is_page(273) ) {
add_action('wp_enqueue_scripts', 'js_custom', 50);
function js_custom() {
wp_register_script( 'js_custom', get_template_directory_uri() . '/js/custom.js', false, null);
wp_enqueue_script( 'js_custom' );
}
}
Why it’s not loaded? I am on the page with the id equal to 273.
I had a similar issue once. I found that running the
add_action
call outside the conditional worked. So try this: