Sybyll
Forum Replies Created
Viewing 2 replies - 1 through 2 (of 2 total)
-
Forum: Fixing WordPress
In reply to: Problem loading script files by pageI found the solution thanks to the link above.
Is someone may interest in it, I post the right code below// I register all my script in 1 function first function organizedthemes_load_default_scripts() { if( !is_admin()){ 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_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); } } add_action('wp_enqueue_scripts', 'organizedthemes_load_default_scripts'); // function with coditions function be_script_it() { // if the page is called/ with slug 'home' the load xx script if(is_page( 'home' ) ){ wp_enqueue_script('booking_language_it'); wp_enqueue_script('booking_searchbox_it'); wp_enqueue_script('booking_modulo'); } // if is not true then load yy script else{ wp_enqueue_script('booking_language_en'); wp_enqueue_script('booking_searchbox_en'); wp_enqueue_script('booking_modulo'); } } add_action('wp_enqueue_scripts', 'be_script_it');As is now the code load the second part of the script in all pages except for ‘home’. In my case I need the scripts in just 2 pages (en+it) and 4 post (en+it), so I changed the second part of my function like this
function be_script_it() { // if is this specific IT page title and this IT posts title then load IT script if(is_page( 'home' )|| is_single( array( 'camera-deluxe', 'camera-classica' ) ) ){ wp_enqueue_script('booking_language_it'); wp_enqueue_script('booking_searchbox_it'); wp_enqueue_script('booking_modulo'); } // if is this specific EN page title and this EN posts title then load EN script if(is_page( 'homepage' )|| is_single( array( 'deluxe-room', 'classic-room' ) ) ){ wp_enqueue_script('booking_language_en'); wp_enqueue_script('booking_searchbox_en'); wp_enqueue_script('booking_modulo'); } // if both cases aren't true then load nothing else{} } add_action('wp_enqueue_scripts', 'be_script_it');Forum: Fixing WordPress
In reply to: Problem loading script files by pageI just read this article about conditional tags in function. Is it right? Should I put the conditional inside the function?
http://www.organizedthemes.com/loading-scripts-conditionally/
Viewing 2 replies - 1 through 2 (of 2 total)