This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 5 replies, has 2 voices.

Last updated by Noman 1 year ago.

Assigned support staff: Noman.

Author Posts
October 4, 2018 at 10:45 am #2787216

frankH-30

Hi,

right now, my Language Switcher in the Header displaying the current Language namen. What I want:

Menu Title -> "Language"
Submenu -> "German" / "English"

Can you help me please?

October 5, 2018 at 11:40 am #2790577

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting WPML support. You can achieve it by creating custom language switcher.

If you are familiar with programming you should not have any problems. Here is a guide that might be helpful:
https://wpml.org/documentation/getting-started-guide/language-setup/custom-language-switcher/
http://wpml.org/documentation/support/wpml-coding-api/

Please let me know if you need further assistance.

Thank you

October 6, 2018 at 8:55 am #2792626

frankH-30

Hi thanks for the links. Unfortunatly my coding is not the best. Maybe you can please provide a codesnippet?? Here is an example structure of my header.php:

<ul>
<li>  Language 

<!-- DYNAMIC PHP CODESNIPPET LIKE:
<ul>
<li>German</li>
<li>English</li>
</ul>
-->

</li>

</ul>



October 8, 2018 at 9:57 am #2795448

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

1. Please add following code in your theme/child theme functions.php file

add_shortcode('get_lang_dropdown', 'get_lang_dropdown_func');
function get_lang_dropdown_func() {
    	 	
    	 	$languages = icl_get_languages('skip_missing=0&orderby=code');
    	 	 if(!empty($languages)){
                	 	 $content = '<ul class="sub-menu" id="select_lang_switch">';
                	 	         	 foreach($languages as $l){
                                        	   	  if($l['country_flag_url']){
                                                            	  $selected = '';
                                                            	  if($l['active']) {
                                                            	         	$selected = "class='active'";
                                                                         	$active_item = '<a href="'.$l['url'].'">'.icl_disp_language($l['native_name'], $l['translated_name']).'</a>';
                                                            	  }
                	 	                                  	$content .= '<li '.$selected.'><a href="'.$l['url'].'">'.icl_disp_language($l['native_name'], $l['translated_name']).'</a></li>';
                                        	   	  }
                	 	         	 }
                	 	 $content .= '</ul>';
    	 	 }
    	 	$content .= '<li> Languages' . $content.'</li>';
    	 	
    	 	return $content;
}

2. To display language switcher in menu, Please add following code in your theme/child theme functions.php file:

add_filter('wp_nav_menu_items','add_search_box_to_menu', 10, 2);
function add_search_box_to_menu( $items, $args ) {
   if( $args->theme_location == 'primary' ) // update menu name
        	return $items. do_shortcode('[get_lang_dropdown]');
}

==> Don’t forget to update ‘primary’ to your menu location.

3. If still issue persists, please provide temporary access (WP-Admin and FTP Login info) to your site (preferably staging site), so that I can look into your setup and debug the issue.

Your next answer will be private which means only you and I have access to it.

=== Please backup your database and website ===

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.

I hope it helps,

Thank you

October 9, 2018 at 9:59 am #2799301

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thanks for the login info. I am working on this issue and get back to you with my findings.

Thank you

October 9, 2018 at 3:02 pm #2800665

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

I have fixed this issue by replacing following code:

if( $args->theme_location == 'right-menu'  ) // update menu name
            return $items. do_shortcode('[get_lang_dropdown]');

With:

if( $args->theme_location == 'right-menu'  ) // update menu name
            return $items. do_shortcode('[get_lang_dropdown]');
	return $items;

And now its not breaking main menu. Could you please check and confirm?

Thank you

The topic ‘[Closed] Want to change the title of the menu displayed in header’ is closed to new replies.