Please make sure to update to WPML 4.3.6 and check our list of Known Issues before reporting

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: Custom langauge switcher not working for logged out users.

Solution: The code was fine but the language was hidden in WPML -> Languages.

Relevant Documentation:

This topic contains 2 replies, has 2 voices.

Last updated by brunoD-31 1 year, 4 months ago.

Assigned support staff: Ricardo Alday.

Author Posts
October 16, 2018 at 1:32 pm #2821124


I am trying to:
Create a custom WPML language switcher in the header of my page

Link to a page where the issue can be seen:
Coming soon, restaging the website

I expected to see:
A language switcher in the top right corner as seen here:
hidden link

Instead, I got:
It's blank if a user is not logged in, or not admin (i'm not sure):
hidden link

Here's the code I used:

The header-logo.php file:
This snippet:
<div class="desktop">
<div id="flags_language_selector"><?php language_selector_flags_opposite(); ?></div >

The functions.php file:
This snippet:
/* Flags but in opposite order */
function language_selector_flags_opposite() {
$languages = icl_get_languages('skip_missing=0');
foreach($languages as $l){
echo '<a href="' . $l['url'] . '"> ' . $l['translated_name'] . ' <img class="country-flag" src="' . $l['country_flag_url'] . '" height="12" alt="' . $l['language_code'] . '" width="18" /></a>';

Why is this not viewable by guests?

October 17, 2018 at 5:46 pm #2825565

Ricardo Alday


Thank you for contacting WPML support.
I tested your code in my local installation and it works, whether I'm logged in or out.

Are the languages hidden by any change on your site?

October 18, 2018 at 10:22 am #2827583


The language was indeed still hidden.

I was developing this function on a staging environment where the language was still hidden.

Issue solved.