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 thread is resolved. Here is a description of the problem and solution.

Problem:Blender theme from ThemeForest generates redundant submenus in the language switcher.

Solution: The theme creates a submenu container for every submenu item in the menu. With the way the langauge switcher is generated it will take quite a bit of work to make it work in this theme. So the work around is to add this code to the child theme functions.php file:

function custom_wpml_menu(){
    $languages = icl_get_languages('skip_missing=0&orderby=code');
    if(!empty($languages)){
        foreach($languages as $l){
            echo '<li>';
            if($l['country_flag_url']){
                echo '<a href="'.$l['url'].'">';
                echo '<img src="'.$l['country_flag_url'].'" height="12" alt="'.$l['language_code'].'" width="18" />';
                echo '</a>';
            }
            echo '</li>';
        }
    }
}

And then add this line to the blender/parts/menu.php file:

custom_wpml_menu();

Right before this lines:

echo "</ul>";
echo '</nav>';

Also, remove the language switcher from WPML -> Languages -> Menu language switcher.

Relevant Documentation: https://wpml.org/documentation/getting-started-guide/language-setup/custom-language-switcher/

This topic contains 6 replies, has 2 voices.

Last updated by davidd-49 12 months ago.

Assigned support staff: Ricardo Alday.

Author Posts
October 15, 2018 at 11:39 am #2817190

davidd-49

I am trying to:
Have a *normal* switcher added to the main menu

Link to a page where the issue can be seen:
hidden link

I expected to see:
The switcher (list format) without any submenu

Instead, I got:
A lot of useless submenus...

I'm pretty sure it's a theme related thing (there's no issue with default wp themes) but I would like to ask you some tips as well. If really needed I'll grant you an access.

October 16, 2018 at 8:12 am #2820005

davidd-49

Not even a suggestion or a word after almost a day?

October 17, 2018 at 2:21 am #2822848

Ricardo Alday

Hi,

Sorry for the late reply, at the moment there is a waiting time of more than 24 hours. We apologize for the inconvenience this causes.

That said, when I visited your site I was faced with a 500 error page so I'm unable to see the issue.
Please check your site so we can view it. Also, if you can upload a copy of the theme to Dropbox or Google Drive so I can test it out and suggest a workaround that would be great.

Thanks,
Ricardo

October 17, 2018 at 7:19 am #2823499

davidd-49

Hello,
500 Error has been fixed, so you can check it again.
If you provide me an address I can give you a WeTransfer url to get the theme...

October 17, 2018 at 10:36 pm #2826037

Ricardo Alday

Thanks. I see the problem. Please use ricardo.a@onthegosystems.com for the WeTransfer url.

October 18, 2018 at 5:19 pm #2829031

Ricardo Alday

Thanks for the copy of the theme.

The theme creates a submenu container for every submenu item in the menu. With the way the langauge switcher is generated it will take quite a bit of work to make it work in this theme. So the work around is to add this code to the child theme functions.php file:

function custom_wpml_menu(){
    $languages = icl_get_languages('skip_missing=0&orderby=code');
    if(!empty($languages)){
        foreach($languages as $l){
            echo '<li>';
            if($l['country_flag_url']){
                echo '<a href="'.$l['url'].'">';
                echo '<img src="'.$l['country_flag_url'].'" height="12" alt="'.$l['language_code'].'" width="18" />';
                echo '</a>';
            }
            echo '</li>';
        }
    }
}

And then add this line to the blender/parts/menu.php file:

custom_wpml_menu();

Right before this lines:

echo "</ul>";
echo '</nav>';

Also, remove the language switcher from WPML -> Languages -> Menu language switcher

Hope that helps.

October 19, 2018 at 8:44 am #2831107

davidd-49

It took more time than I thought but the issue is resolved now.
Thanks for your help!