This thread is resolved. Here is a description of the problem and solution.
Problem:
The customer wants to remove the trailing slash from the home page hreflang.
Solution:
You should be able to remove the trailing slash using the “wpml_alternate_hreflang” filter.
Relevant Documentation:
https://wpml.org/wpml-hook/wpml_alternate_hreflang/
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: Not WPML issue
This topic contains 6 replies, has 2 voices.
Last updated by elizabethU-2 1 year, 11 months ago.
Assisted by: Noman.
Author | Posts |
---|---|
January 11, 2023 at 3:36 pm #12796959 | |
elizabethU-2 |
hreflang on the homepage: provenir.com is adding a trailing slash when it shouldn't be. Can you advise? |
January 11, 2023 at 4:05 pm #12797197 | |
Noman Supporter
Languages: English (English ) Timezone: Asia/Karachi (GMT+05:00) |
Hi, Thank you for contacting WPML Support. 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: 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. Right now it's working without any issues. Thank you |
January 11, 2023 at 4:56 pm #12797615 | |
elizabethU-2 |
Can you help me update this bit? if ( is_front_page() || is_home() ){ To target hidden link only I don't want it to affect provenir.com/es/ or provenir.com/bt-br/ etc Thanks, Jonny |
January 12, 2023 at 8:14 am #12801481 | |
Noman Supporter
Languages: English (English ) Timezone: Asia/Karachi (GMT+05:00) |
Thanks for getting back to me. In this case, you can apply the code based on the default language code that is a second parameter of our function and it will look like this: 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() ) && $lang_code == 'en' ){ $url = rtrim($url, '/'); } return $url; } Could you please try and let me know how it goes? Thank you |
January 12, 2023 at 10:22 am #12803255 | |
elizabethU-2 |
That works like a dream! The only remaining SEO issue now is regarding our paginated pages: Example: hidden link These should not have hreflang tags at all as they are not translations. The English site might have 30 pages or blogs, but the Portuguese site only has 10 pages and the order is completely different. Can you help us remove hreflang from paginated pages as per the example? New threads created by Noman and linked to this one are listed below: |
January 12, 2023 at 4:10 pm #12807255 | |
Noman Supporter
Languages: English (English ) Timezone: Asia/Karachi (GMT+05:00) |
Glad to hear your trailing slash on the home page issue is solved. Regarding the SEO issue on paginated pages, it's a different issue and will be handled separately as per our support policy. I have created a new ticket for this: If your current ticket issue is resolved, you may mark this ticket as resolved and we will continue to work on the new ticket. Thank you for your cooperation and patience. |