Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
You need to redirect the root URL of your website to a language-specific version using WPML, but you are unable to create a template for the redirection.
Solution:
1. First, create a PHP template in your site’s theme folder. You can name it 'Root redirect'. It's recommended to add PHP files to a child theme. For more details on creating custom page templates, visit Creating Custom Page Templates for Global Use.
2. Add the following content to your new PHP page template file:

<?php
/*
Template Name: Root redirect
*/
wp_redirect( home_url() );
exit;
?>

3. Edit your root page and in the right sidebar, expand the Summary section and select the template you just created.
4. Update the page.

If this solution does not resolve your issue, or if it seems outdated or irrelevant to your case, we recommend opening a new support ticket. Also, check related known issues at https://wpml.org/known-issues/, verify the version of the permanent fix, and confirm that you have installed the latest versions of themes and plugins. For further assistance, please visit our support forum at WPML Support Forum.

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.

Our next available supporter will start replying to tickets in about 11.10 hours from now. Thank you for your understanding.

This topic contains 5 replies, has 2 voices.

Last updated by Andrey 1 month, 3 weeks ago.

Assisted by: Andrey.

Author Posts
July 30, 2024 at 5:24 pm #16021764

vincentL-45

Background of the issue:
I would like to redirect the root hidden link to hidden link. I tried all explained on your website but the thing I can't do, it's create a template to do the redirection. I need help on that. I read the documentation.

Symptoms:
I can't create a template to do the redirection.

Questions:
How can I redirect the root hidden link to hidden link using WPML?
What steps are needed to create a template for redirection in WPML?

July 30, 2024 at 7:49 pm #16022141

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kyiv (GMT+03:00)

Have you attempted to follow this section of the documentation?

https://wpml.org/documentation/getting-started-guide/language-setup/directory-default-language/#redirect-the-root-domain-to-the-default-language-directory

What specific steps are causing you difficulty? Could you please show me?

July 30, 2024 at 7:53 pm #16022161

vincentL-45

Yes I tried...
I am not able to create the needed template to set the redirection.

July 30, 2024 at 9:44 pm #16022507

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kyiv (GMT+03:00)

Please explain step by step so I can assist you further.

July 31, 2024 at 11:35 am #16024707

vincentL-45

Simple...

I choose "Different languages in directories".

I selected : "A page 'Edit root page'.".

I don't want my visitors go to astuce-credit.be and see my root page.

I want when they arrive on astuce-credit.be that they are automatically redirected to astuce-credit.be/fr/

July 31, 2024 at 9:22 pm #16026969

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kyiv (GMT+03:00)

Thank you for your feedback.

Here is an outline of the steps:

1. Create a PHP template (https://developer.wordpress.org/themes/template-files-section/page-template-files/#creating-custom-page-templates-for-global-use) in your site’s theme folder. Calling it, for example, Root redirect (Template Name: Root redirect). In most cases, you should add such PHP files to a child theme.

2. So, you need to add the following content to your new PHP page template file:

<?php
/*
Template Name: Root redirect
*/
wp_redirect( home_url() );
exit;
?>

3. Now, go back and edit your root page. In the right sidebar, expand the Summary section and select the template you just created.

4. When you’re done, make sure to update the page.

I hope this helps.

wpml-template-root-redirect.png
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.