Problem loading script files by page
-
Hi,
I think I’m doing something wrong here, not sure what tho.
So, I have followed your instruction on this forum post, codex.. everywhere (by the way thanks guys you’re an awesome resource) and I manage to write down this code for including some scripts in the footer.The function works fine, but my site is bilingual so I create 2 function with the condition if(is_page( ‘slug’ ) ) add_action xx else add-action yy, where the slug ‘homepage’ is the english version of the page.
For some reasons the conditional results always false so the script loaded is never in english.
I tested the function with other slugs, same problem. Could this happening because I’m using Polylang to translate the website?
With this plugin my url changes from site_url/page_slug/ to site_url/en/page_slug/
The plugin documentation https://polylang.wordpress.com/documentation/
Here is my function:
<?php // Italian scripts function be_script_it() { wp_register_script( 'booking_language_it', get_template_directory_uri() . '/globalize/globalize-it.js', array( 'jquery' ), null , true); wp_register_script( 'booking_searchbox_it', 'https://be.bookingexpert.it/book/websites/searchbox?hotel=5098&lang=it', array (), null , true); wp_register_script( 'booking_modulo', get_template_directory_uri() . '/globalize/searchbox.js', array (), null , true ); wp_enqueue_script('booking_language_it'); wp_enqueue_script('booking_searchbox_it'); wp_enqueue_script('booking_modulo'); } // English scripts function be_script_en() { wp_register_script( 'booking_language_en', get_template_directory_uri() . '/globalize/globalize-en.js', array( 'jquery' ), null , true); wp_register_script( 'booking_searchbox_en', 'https://be.bookingexpert.it/book/websites/searchbox?hotel=5098&lang=en', array (), null , true); wp_register_script( 'booking_modulo', get_template_directory_uri() . '/globalize/searchbox.js', array (), null , true ); wp_enqueue_script('booking_language_en'); wp_enqueue_script('booking_searchbox_en'); wp_enqueue_script('booking_modulo'); } // conditions if the slug page is homepage (en version page) if(is_page( 'homepage' ) ) add_action('wp_enqueue_scripts', 'be_script_en'); else add_action('wp_enqueue_scripts', 'be_script_it'); ?>
The topic ‘Problem loading script files by page’ is closed to new replies.