Title: Help with Drop-down action
Last modified: August 21, 2016

---

# Help with Drop-down action

 *  Resolved [Genevieve](https://wordpress.org/support/users/sweetgenevieve/)
 * (@sweetgenevieve)
 * [13 years ago](https://wordpress.org/support/topic/help-with-drop-down-action/)
 * I’m trying to use `<?php pll_the_languages(array('dropdown'=>1)); ?>` to display
   a language switcher drop-down in my theme, and I found the widget’s drop-down
   action code in polylang/include/widget.php, but I can’t get it to work. The action
   code kills the whole page. This is how I’m using it:
 *     ```
       <?php pll_the_languages(array('dropdown'=>1)); ?>
       <?php foreach ($polylang->get_languages_list() as $language) {
       				$url = $force_home || ($url = $polylang->get_translation_url($language)) == null ? $polylang->get_home_url($language) : $url;
       				$urls[] = '"'.esc_js($language->slug).'":"'.esc_url($url).'"';
       			}
   
       			$urls = implode(',', $urls);
   
       			$js = "
       				<script type='text/javascript'>
       					//<![CDATA[
       					var urls = {{$urls}};
       					var d = document.getElementById('lang_choice');
       					d.onchange = function() {
       						for (var i in urls) {
       							if (this.value == i)
       								location.href = urls[i];
       						}
       					}
       					//]]>
       				</script>";
   
       			echo $js;
       		} ?>
       ```
   
 * Any help would be greatly appreciated!
 * [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 ago](https://wordpress.org/support/topic/help-with-drop-down-action/#post-3682994)
 * You must add
 *     ```
       global $polylang;
       ```
   
 * before your `foreach`
    I also believe that you must remove the last `}`
 *  Thread Starter [Genevieve](https://wordpress.org/support/users/sweetgenevieve/)
 * (@sweetgenevieve)
 * [13 years ago](https://wordpress.org/support/topic/help-with-drop-down-action/#post-3683004)
 * That worked! Thanks so much!
 * So, for those looking to do the same thing as me, this is what my final code 
   looks like:
 *     ```
       <div><?php if(function_exists('pll_the_languages')) {
       		pll_the_languages(array('dropdown'=>1));
       	} ?></div>
       	<?php global $polylang;
       		foreach ($polylang->get_languages_list() as $language) {
       				$url = $force_home || ($url = $polylang->get_translation_url($language)) == null ? $polylang->get_home_url($language) : $url;
       				$urls[] = '"'.esc_js($language->slug).'":"'.esc_url($url).'"';
       			}
   
       			$urls = implode(',', $urls);
   
       			$js = "
       				<script type='text/javascript'>
       					//<![CDATA[
       					var urls = {{$urls}};
       					var d = document.getElementById('lang_choice');
       					d.onchange = function() {
       						for (var i in urls) {
       							if (this.value == i)
       								location.href = urls[i];
       						}
       					}
       					//]]>
       				</script>";
   
       			echo $js;
       	?>
       ```
   

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

The topic ‘Help with Drop-down action’ 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/)

 * 2 replies
 * 2 participants
 * Last reply from: [Genevieve](https://wordpress.org/support/users/sweetgenevieve/)
 * Last activity: [13 years ago](https://wordpress.org/support/topic/help-with-drop-down-action/#post-3683004)
 * Status: resolved