Skip Navigation

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

Problem:
The client's domain is configured sitewide without a trailing slash, but the alternate link for the main page includes one, causing inconsistency.
Solution:
If you're experiencing this issue, we recommend the following steps:

  1. Ensure you back up your site for safety reasons.
  2. Add the following code to your
    functions.php

    file:

    add_filter('wpml_alternate_hreflang', 'custom_wpml_alternate_hreflang_func', 10, 2);<br />function custom_wpml_alternate_hreflang_func($url, $lang_code) {<br />    if (is_front_page() || is_home()) {<br />        $url = rtrim($url, '/'); <br />    }<br />    return $url;<br />}

For more details, refer to the documentation on WPML alternate hreflang and is_front_page.

Please note that this solution might be outdated or not applicable to your case. We highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the issue persists, please open a new support ticket.

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.

Tagged: 

This topic contains 1 reply, has 0 voices.

Last updated by mathiasZ-2 2 weeks, 2 days ago.

Assisted by: Bobby.

Author Posts
March 24, 2025 at 5:58 pm #16853618

mathiasZ-2

Background of the issue:
My domain is configured sitewide without a trailing slash, but the alternate link includes one: <link rel="alternate" hreflang="en" href="hidden link" />. This applies only to the main page.

Symptoms:
The alternate link for the main page includes a trailing slash, while the domain is configured without it.

Questions:
What can I do about the trailing slash in the alternate link for the main page?

March 25, 2025 at 8:41 pm #16859869

Bobby
WPML Supporter since 04/2015

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hi There,

You should be able to remove the trailing slash using the “wpml_alternate_hreflang” filter. So, here will be the steps:

1. Please make sure to take a backup of your site first for safety reasons.

2. Please add the below code in the functions.php file:

add_filter('wpml_alternate_hreflang', 'custom_wpml_alternate_hreflang_func', 10, 2);
function custom_wpml_alternate_hreflang_func($url, $lang_code) {
    
    if ( is_front_page() || is_home() ){
        $url = rtrim($url, '/'); 
    }
    return $url;
}

Here are docs for more details:
https://wpml.org/wpml-hook/wpml_alternate_hreflang/
https://developer.wordpress.org/reference/functions/is_front_page/

Please understand that I'm helping you here with an issue that is out of the scope of our support forum and we will not be able to support this particular fix in the future. Because the theme or our code might have changed, so please always be aware of this.

Let me know your results, please.

April 1, 2025 at 10:14 am #16882227

mathiasZ-2

thanks 🙏

April 1, 2025 at 10:14 am #16882228

mathiasZ-2

thanks 🙏