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 3 replies, has 2 voices.

Last updated by Andreas W. 6 months, 1 week ago.

Assigned support staff: Andreas W..

Author Posts
April 13, 2019 at 4:09 pm #3605091

nicolaP-13

I am trying to:
show the language switcher in root page via do_action('icl_language_selector')

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

I expected to see:
The language selector.

Instead, I got:
No language selector, even if "Hide language selector in the main page" is unchecked under language folder settings. It seems to work only checking "Link to home of language for missing translations" (as checked right now if you visit the link I provided, so the problem is temporarily not visible right now, but still occurring as the client don't want this option to be checked permanently).

I guess the problem is due to that the root page is not supposed to be the default language home page so is not translated (the root page) out of the box (I had hard time as many others over the years to overcome that).

Last fix I would need is a way to target the wpml root page in header.php (as per wordpress' is_front_page() or something like that) so I can at least write a vanilla html language switcher that point to the languages home folders to emulate the one dinamically generated by WPML across the other pages.

Thanks for your time, the current handling of root page is maybe the only troubleshooting option of this otherwise brilliant plugin. Any suggestion to address this problem is welcome.

April 13, 2019 at 6:38 pm #3605381

Andreas W.
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

Thank you for contacting WPML Support.

I would advise you to activate the option for a custom language switcher at WPML -> Languages.
https://wpml.org/documentation/getting-started-guide/language-setup/language-switcher-options/

There are various ways to inlcude the custom language switcher. The most common would be to include it inot the themes functions.php or by shortcode. You can find more detailed information here:
https://wpml.org/documentation/getting-started-guide/language-setup/custom-language-switcher/

Let me know if you got any further questions.

Kind regards
Andreas

April 16, 2019 at 8:54 am #3620121

nicolaP-13

Hello Andreas,

I tried activating a Custom language switcher as you suggested and I've replaced the do_action('icl_language_selector') with do_action('wpml_add_language_selector') as stated in the documentation, but still not working with .

I guess, AFAIK, my issue is due to how WPML handle root page: if both "Skip language" option and folder languages with folder for main translation are in use, WPML can't find a translation for the root (even if the page selected as root is translated, but only under the /language/ ) so the switcher is not generated at all.

That's why I was in need to target specifically the root page with a funciont (as the WordPress 'is_front_page' for instance).

Considering I'm already using a specific page template for the home I guess I'll try to handle the header using custom code to check if the url is the one for the root, then I'll output an html switcher identical to the one generated via WPML in order to keep consistency.

I'll let you know as soon as I'll be able to do it.

April 16, 2019 at 5:31 pm #3624267

Andreas W.
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

As for the hook to activate the language switcher you did right as far I can tell.
https://wpml.org/wpml-hook/wpml_add_language_selector/

Did you create a new template file for your root page or are you using a given page?
https://wpml.org/documentation/getting-started-guide/language-setup/directory-default-language/

You could place a custom html on your root page including the code for the custom language switcher. Then activate the custom language switcher in WPML -> Languages and modify it.

More information about custom language switchers you can find here:
https://wpml.org/documentation/getting-started-guide/language-setup/custom-language-switcher/

This code should give you a language switcher with flags only:

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

Please also check that there is an option on WPML -> Languages -> Language URL Format that lets you hide the language switcher on root pages. Make sure it is unmarked.

You also could assign custom links to the root page menu:
hidden link

I would like to request temporary access (wp-admin and FTP) to your site to take a better look at the issue. It would be better to a testing site where the issue is replicated.

You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

Maybe I'll need to replicate your site locally. For this, I’ll need to temporarily install a plugin called “Duplicator” on your site. This will allow me to create a copy of your site and your content. Once the problem is resolved I will delete the local site. Let me know if this is ok with you.

IMPORTANT

Please make a backup of site files and database before providing us access.
If you do not see the wp-admin/FTP fields this means your post & website login details will be made PUBLIC. DO NOT post your website details unless you see the required wp-admin/FTP fields. If you do not, please ask me to enable the private box. The private box looks like this:
hidden link

Kind regards
Andreas

The topic ‘[Closed] Missing language switcher in root page’ is closed to new replies.