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:

I have a custom template as part of my Divi child theme, but I get a 404 error if I include "lang=es" in the query string.

Solution:

The post was not translated so it needed to be translated. In this case, it was also recommended to change the Language URL format to 'Different languages in directories'

This topic contains 6 replies, has 2 voices.

Last updated by Itamar 3 months, 1 week ago.

Assigned support staff: Itamar.

Author Posts
July 16, 2019 at 12:36 am #4214841

rebeccaD

I am trying to:
I have a custom template as part of my Divi child theme but I get a 404 error if I include "lang=es" in the query string.

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

I expected to see:
The same thing that you would see (except with the menu/logo in Spanish) here:
hidden link

Instead, I got:
a 404 error - it's apparently not even making it to the feast-day.php file.

July 16, 2019 at 7:20 am #4216963

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi.

I can see the issue on your site at this link.
hidden link
I can see the English (default language) version of this page is working fine.
hidden link

Please let me ask you a few questions.

1. Is the English version of this page is translated into Spanish or are you just adding the language parameter at the end and expecting it to work?

2. Can you please elaborate on those URL arguments that you are passing?

3. Are those URL arguments permanent or change all the time?

4. This might work if you switch the 'Language URL format' in WPML -> Languages to 'Different languages in directories'
Do you have the possibility to do that?
It is even recommended SEO-wise.

Regards,
Itamar.

July 16, 2019 at 4:14 pm #4222157

rebeccaD

Hi Itamar,

Here are my answers to your questions:

1. feast-day.php is a custom template that I programmed myself in php, and it resides in my child theme folder (a child of the Divi theme). It calles all the same standard headers that Divi's default template calls, I just added my custom content in main body of the page. Then it calls the footer, like every other page. Since I don't know the underworkings of WPML, I'm expecting that, since all the other pages just pass the "lang=es" argument, that this page would load the appropriate headers based on that argument. My code itself is currently not processing "lang=es" which is why the page is currently bilingual instead of just Spanish.

2. The URL arguments are really arbitrary except for the "lang=es" since that's the one that WPML is using to intercept the link and not let it be handled by my custom php template.

3. The url arguments do change - it's to specify changes for different days of the year over 3 yearly cycles. Again, it's arbitrary. I *could* use a completely different argument to define that the page is in Spanish, say "lan=esp" but then the header and footer (which have translated logos and menus for Spanish) would have to be manually pulled in. And I'm not necessarily against that but I don't know which php calls will work - again, I don't know how WPML interjects itself into the page hierarchy, so that's why I'm forced to reach out for help. 🙂

4. I already looked into potentially changing the URL format but the attached screenshot will give you a better idea of why I haven't done that.

Also, I'd *really* like to know how WPML is handling everything. I've been snooping around in the developer docs but I haven't quite found a clear explanation.

Thank you!

July 17, 2019 at 9:03 am #4227945

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi and thanks for the detailed explanation.

First, it is essential for me to mention that helping with a custom code of themes and plugins is out of the scope of this forum. Nevertheless, I am obligated to help you if you are using one of our API hooks, and something is not working for you as expected. Our documentation on hooks can be found here.
https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/
Also, the following documentation might be relevant in your case.
https://wpml.org/documentation/support/wpml-coding-api/
And I think that you already know the parent developers' section here.
https://wpml.org/documentation/support/

You wrote: "I'd *really* like to know how WPML is handling everything. I've been snooping around in the developer docs, but I haven't quite found a clear explanation."

Please understand that WPML and its add-ons are very complex plugins. You can find all our documentation at the link above. But I can only comment on a specific question that you might have. It is very hard for me (and I don't think that I can) to explain to you how WPML works.

In WPML -> Languages -> Language switcher options, you can find the 'Preserve URL arguments' option. Since you say that the URL parameters are arbitrary, I'm not sure if this option can help you, but please check our documentation about it at the following link.
https://wpml.org/documentation/getting-started-guide/language-setup/language-switcher-options/#preserving-url-parameters

Other than that, I didn't understand from you if the page that you sent me as an example is translated or not. Can you please tell me about it?

In general, my strong recommendation in this case (and in general) would be to switch to the option 'Different languages in directories' in WPML -> Languages -> Language URL format. When this does not work, it is most likely a server issue. Please review our documentation here and let me know if you want to go in this direction to solve the issue that you are having.
https://wpml.org/faq/server-setting-for-languages-in-directories/
Note: you might need to get the help of your hosting service on this issue.

Regards,
Itamar.

July 17, 2019 at 3:31 pm #4231781

rebeccaD

Hi Itamar,

Thank you fro taking the time to write such a detailed and helpful reply. You were right that the Page was not translated and when I added the translation, it worked *better* BUT then I found that my custom post types were totally ruined because of the way WPML translates media types. This particular site has loads of data indexed using custom post types and I just had to back out of WPML completely. It's just overly complicated for what is needed on this site.

Anyway, I will still use WPML for a couple other simpler sites where I can start from scratch. I will take your recommendation for using the Different Languages in different directories option. Also, I know now to install WPML, *disable* custom post type translation, and *then* install the custom post types so WPML doesn't interject itself where it is not wanted. That was my fault for not understanding your plugin better.

So thank you for your help!

July 17, 2019 at 3:32 pm #4231789

rebeccaD

Thank you!

July 17, 2019 at 3:34 pm #4231797

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

You are welcome. I'm glad that the information that I gave you was somewhat helpful.
Please feel free to contact us again here in the support forum with any WPML issue.

Best Regards,
Itamar.