1

this is not a question but -hopefully- an answer. I realized that more than a couple of people on the WPML forum asked for a solution to this matter, so I thought it could be useful to share my workaround here as I did there.

The Issue

Let's say that for whatever reason you need to disable the WPML language switcher just for a specific page, or even for all posts, or all single pages in a category... literally for any reason.

For example I have a menu M1 in position m-1 with Home | about us | contact us, and with the switcher SW1 assigned to it via the WPML > languages page; let's say that I don't want SW1 to appear when I'm in the about us page.

The workaround

I just register another menu M2 -which is the exact copy of M1- and assign it to position m-2.

At this point I already have total control in my template files upon where and when SW1 will appear, using WordPress conditional tags or whatever other PHP condition.

For example in page.php I can do:

if ( is_page( 'about-us' ) ) {
    wp_nav_menu( array( 'theme_location' => 'm-2', (...etc) ) );
} else {
    wp_nav_menu( array( 'theme_location' => 'm-1', (...etc) ) );
}

Now SW1 will appear only when we are not in the about us page since it's assigned to m-1 and about us picks m-2.

Trivia

I had to found this workaround because WPML had problems with CPT date archives and I needed a fast idea. More specifically, if I had, say, "mysite.com/it/mia-pagina/2020/" I couldn't find a way to go to "mysite.com/en/my-page/2020/" via the default switcher (N.B. I had already enabled the date archives for CPTs thanks to a third party plugin that just adds the rewrite rules that in WordPress are missing for this scenario).

Funny enough, I could go to the desired page if I just manually wrote its url in the browser. It's just that the WPML switcher's link failed in this specific case.

So without the time to wait for a core update or for a deep and slow programming, I needed to disable the default WPML language switcher just for CPT date archives and substitute it with a custom one.

Hope it helps!

4
  • Sorry for the rough incipit but for some reason this editor strips out my initial "Hello everyone". I've tried like 200 times, I give up. – Marks Jul 17 '20 at 12:19
  • This isn't a Discussion forum, but a Q&A site. You can post a question and then post its answer below, otherwise the question is marked as unanswered. Unfortunately WPML as a 3rd party plugin is offtopic here – Tom J Nowell Jul 17 '20 at 12:58
  • Hello Tom, thanks for your intervention, I've been inattentive on this site's purpose. I guess I could edit the post as a Q&A section, if you don't mind: I still think that the solution being a WordPress only one, it could fit well in this site. But of course I'll wait for a final "yes" (I'll edit the post) or "no" (I'll delete it) from you. – Marks Jul 17 '20 at 16:39
  • There are only questions and answers here, that's what stackoverflow and the stack exchange sites are. Since the question is closed there is no need to delete it – Tom J Nowell Jul 17 '20 at 21:28