Title: JavaScript not loading when switching languages
Last modified: August 20, 2016

---

# JavaScript not loading when switching languages

 *  Resolved [KeenanPayne](https://wordpress.org/support/users/keenanpayne/)
 * (@keenanpayne)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/javascript-not-loading-when-switching-languages/)
 * Hello,
 * I was working on a website for a client ([http://www.infiniacorp.com](http://www.infiniacorp.com))
   and am using the Polylang plugin to switch between English, Spanish, and Italian.
    - [http://www.infiniacorp.com/en](http://www.infiniacorp.com/en)
    - [http://www.infiniacorp.com/es/](http://www.infiniacorp.com/es/)
    - [http://www.infiniacorp.com/it/](http://www.infiniacorp.com/it/)
 * The homepage pulls in static content from pages and as you can see on the English
   and Spanish versions, the drop-down menu and background slider work fine. However,
   on the Italian version, it does not.
 * Here is the custom PHP I am using to pull in the content from pages, and check
   which language the site is using:
 *     ```
       <?php
       		$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
       		if (false !== strpos($url,'es')):
       			$page_id = 788;
       		elseif (false !== strpos($url,'it')):
       			$page_id = 1031;
       		else:
       			$page_id = 784;
       		endif;
       	?>
   
       	<?php
       		$page_data = get_page( $page_id );
       		echo apply_filters('the_content', $page_data->post_content);
       	?>
       ```
   
 * This just checks what language code is in the URL, and sets the correct page 
   ID for the given language. This code worked fine with just English and Spanish,
   but when I added Italian, it didn’t work completely.
 * Just to give you a little more background on my custom code, the background is
   supposed to be an image slider (this is not a theme I developed myself) so in
   the backend of WordPress I created multiple sliders for each language, and used
   this code to display them:
 *     ```
       <?php
       $url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
       if (false !== strpos($url,'es')): //If spanish
       	$featured_page_language = 808;
       elseif (false !== strpos($url,'it')): //If italian
       	$featured_page_language = 1033;
       else: //If English
       	$featured_page_language = $featured_page;
       endif;
       ?>
       ```
   
 * Very similar to the code above. It stores the ID of the slider and should display
   it, except it just doesn’t work for Italian.
 * All of the inner pages and everything work fine, it’s just this homepage that’s
   not doing it.
 * I would appreciate any help in fixing this, and thank you for developing such
   a great plugin. I would gladly shoot you over a donation if you could help me
   resolve this.
 * Best,
    Keenan
 * [http://wordpress.org/extend/plugins/polylang/](http://wordpress.org/extend/plugins/polylang/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/javascript-not-loading-when-switching-languages/#post-3595475)
 * > I would gladly shoot you over a donation if you could help me resolve this
 * The support on this forum is free. Donations to plugin authors should not be 
   done in exchange of any support. See: [http://codex.wordpress.org/Forum_Welcome#Offering_to_Pay](http://codex.wordpress.org/Forum_Welcome#Offering_to_Pay)
 * To your problem now. For me the Italian page loads correctly (It looks like the
   content is in Italian). But the slideshow does not load correctly. Looking at
   the source code of your English page, pictures are defined in your slideshow (
   I replaced all urls by …):
 *     ```
       slides 					:  	[			// Slideshow Images
       {image : ...}		],
       ```
   
 * when there is none for the Italian page:
 *     ```
       slides 					:  	[			// Slideshow Images
       		],
       ```
   
 * So I would rather look at the way you defined the Italian pictures for your slideshow.
 * Moreover, I believe that your tests are not very robust:
 *     ```
       if (false !== strpos($url,'/es/')):
       ```
   
 * would be better.
 * Or you can let Polylang do the job itself (if pages are translations of each 
   other), suppress the tests and call:
 *     ```
       $page_data = function_exists('pll_get_post') ? get_page(pll_get_post(784)) : get_page( 784 );
       ```
   
 *  Thread Starter [KeenanPayne](https://wordpress.org/support/users/keenanpayne/)
 * (@keenanpayne)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/javascript-not-loading-when-switching-languages/#post-3595578)
 * Chouby,
 * Thank you very much for your help. I looked in the source and saw that the images
   weren’t being pulled in, and I have no idea why. I re-created the Italian version
   and all of the posts and content, but I still couldn’t get it to work. I had 
   to hack the theme and do this:
 *     ```
       slides 					:  	[			// Slideshow Images
   
       		<?php
       			if (false !== strpos($url,'/it/')): //If italian
       				echo "{image : 'http://www.infiniacorp.com/wp-content/uploads/2012/06/infinia_slideshow_009.jpg', title : '<div class=\"slideshow_title\">Tecnologia Solare d’avanguardia </div>', thumb : 'http://www.infiniacorp.com/wp-content/uploads/2012/06/infinia_slideshow_009-60x60.jpg', url : ''},{image : 'http://www.infiniacorp.com/wp-content/uploads/2012/06/infinia_slideshow_013.jpg', title : '<div class=\"slideshow_title\">Progetti su vasta scala e località remote.</div>', thumb : 'http://www.infiniacorp.com/wp-content/uploads/2012/06/infinia_slideshow_013-60x60.jpg', url : ''},{image : 'http://www.infiniacorp.com/wp-content/uploads/2012/06/infinia_slideshow_008.jpg', title : '<div class=\"slideshow_title\">Alto rendimento del motore di Stirling</div>', thumb : 'http://www.infiniacorp.com/wp-content/uploads/2012/06/infinia_slideshow_008-60x60.jpg', url : ''},{image : 'http://www.infiniacorp.com/wp-content/uploads/2012/06/infinia_slideshow_003.jpg', title : '<div class=\"slideshow_title\">Cambiando il modo in cui il mondo utilizza energia</div>', thumb : 'http://www.infiniacorp.com/wp-content/uploads/2012/06/infinia_slideshow_003-60x60.jpg', url : ''},{image : 'http://www.infiniacorp.com/wp-content/uploads/2012/06/infinia_slideshow_004.jpg', title : '<div class=\"slideshow_title\">Motore e potenza aziendale nelle persone</div>', thumb : 'http://www.infiniacorp.com/wp-content/uploads/2012/06/infinia_slideshow_004-60x60.jpg', url : ''}	";
       			endif;
       ```
   
 * In order to get any slides to show up. I mean I guess it works. Thanks for the
   heads up on my language tests, I got those changed to make them a little more
   robust.
 * Best,
    Keenan

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘JavaScript not loading when switching languages’ is closed to new replies.

 * ![](https://ps.w.org/polylang/assets/icon-256x256.png?rev=3433336)
 * [Polylang](https://wordpress.org/plugins/polylang/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/polylang/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/polylang/)
 * [Active Topics](https://wordpress.org/support/plugin/polylang/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/polylang/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/polylang/reviews/)

## Tags

 * [content](https://wordpress.org/support/topic-tag/content/)
 * [Customizations](https://wordpress.org/support/topic-tag/customizations/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [languages](https://wordpress.org/support/topic-tag/languages/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * 2 replies
 * 2 participants
 * Last reply from: [KeenanPayne](https://wordpress.org/support/users/keenanpayne/)
 * Last activity: [13 years, 2 months ago](https://wordpress.org/support/topic/javascript-not-loading-when-switching-languages/#post-3595578)
 * Status: resolved