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 1 reply, has 2 voices.

Last updated by Raja Mohammed 11 months ago.

Assigned support staff: Raja Mohammed.

Author Posts
July 7, 2019 at 2:49 pm #4157827


Tell us what you are trying to do?
Currenty, I'm working on a project where we are creating custom urls and pages without having a page/post within WordPress. We are using the WordPress hook `do_parse_request` and simple giving custom content back to the browser.

What I'd like to do now, is to tell WPML the target urls for all languages included in the language switcher (and I'm hoping, WPML will also pass these urls to the hreflang headers). So for example I've configured en, de, fr and I'd like to tell WPML for en, please use x, for de, please use y and for fr, please use z.

At the moment, the language switcher is falling back to the home url, as long as I'm on one of the custom pages.

Is there any documentation that you are following?
Is there a similar example that we can see?
I tried it by using this post: - but the hook does not get called.

What is the link to your site?
It is internal only at the moment. If an example is needed, I could prepare a separate minimal example.

July 8, 2019 at 11:07 am #4161679

Raja Mohammed

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi there,

As far as I understand, you are trying to replace the language codes with a dummy text which means you are replacing the language code with a nonexisting language configured in your site and hence the language switcher redirects the request to the home URL based on the settings in WPML > languages > Language Switcher.

Since you have a mapped a dummy language code to an existing code the request needs to parsed again to the active language of the site after the language switcher action is triggered.
So in you have mapped en with x then the language switcher will try to load the page with the language code of x, To resolve this the x needs to be converted back to en so that the language switcher loads the exact contents.

The best I can suggest is to use a custom language switcher which will enable you to manipulate the request to a certain extent

Unfortunately, this falls out of the scope of our support but you can check out our Certified Contractors list as they will be prepared to help you with any custom coding you need related to WPML. The list can be found here:

Kind regards