I have multiple js scripts in separate files which must be fired on different pages. they are executed in the footer using wp_enqueue_script(). They work but not consistently. I even added setTimeout to make sure they load last as they have to fill up some fields in the body. Why is it not firing sometimes?
Is there anything wrong here?
// passenger elevators
add_action('wp_enqueue_scripts', 'passen_elev_custom_js');
function passen_elev_custom_js() {
if( is_page( 4744 ) ) {
wp_enqueue_script('passenger-elevators', 'https://mywebsite.com/passenger-elevators.js',
array(), false, true);
}
}
// home elevators
add_action('wp_enqueue_scripts', 'home_elev_custom_js');
function home_elev_custom_js() {
if( is_page( 5231 ) ) {
wp_enqueue_script('home-elevators', 'https://mywebsite.com/home-elevators.js',
array(), false, true);
}
}
// observation elevators
add_action('wp_enqueue_scripts', 'obs_elev_custom_js');
function obs_elev_custom_js() {
if( is_page( 5343 ) ) {
wp_enqueue_script('observation-elevators', 'https://mywebsite.com/observation-elevators.js',
array(), false, true);
}
}
Aucun commentaire:
Enregistrer un commentaire