I’m trying to add language option to my website. I’ve coded my theme and I need to show the web in three different languages. I’ve got the little flags and I’ve managed to pass a php variable with the language it’s selected. With that variable I’ve made a if for the wp_nav_menu assignment in the header.php. It works actually. When I change the language the correct menu in the correct language comes up. The problem is that when I hit in a menu item and the selected page opens the menu is gone. Disappears. Can anybody help me, plase? Here is the code I use.
In header.php
if ($language == 'en') {
wp_nav_menu(array(
'theme_location' => 'eng',
'container_class' => 'main-nav',
'container' => 'nav'
));
} else if ($language == 'de') {
wp_nav_menu(array(
'theme_location' => 'ger',
'container_class' => 'main-nav',
'container' => 'nav'
));
} else {
wp_nav_menu(array(
'theme_location' => 'esp',
'container_class' => 'main-nav',
'container' => 'nav'
));
}
And in the functions.php
add_theme_support ('menus');
//Create Nav Menu
if (function_exists ('register_nav_menus')) {
register_nav_menus (array(
'esp' => 'Spanish menu',
'eng' => 'English menu',
'ger' => 'Deutsch menu'
));
}
And the html for the flag link in header.php
<li><a href="http://localhost/wordpress/inicio?language=es" ><img src="http://localhost/wordpress/wp-content/themes/wordpressthemeAPI2/img/espflag.PNG" width="18" height="12" onmouseover="this.src='http://localhost/wordpress/wp-content/themes/wordpressthemeAPI2/img/espH.PNG'" onmouseout="this.src='http://localhost/wordpress/wp-content/themes/wordpressthemeAPI2/img/espflag.PNG'"></a></li>
I am not sure that you have provided enough information for solving this issue, it is unclear why and when your menu disappears and under what conditions.
I am not sure why you are registering all the menus, when you probably need one.
I can only advise you to use a plugin that manages languages on the site, there are many options that will probably make this a bit easier for you.
If you provide more information or a test url, I will be happy to take another look
Good luck,
Thanks for your interest.
Actually what happens is that when you hit on a emnu button it takes you to the correct page, but the menu changes to the spanish language wich, I supose looking at the code, is set sort of default.
Here you have a link to have a look to what I’m trying to do. Thank you!
http://ibizaonlinerentals.com/newweb/