Skip Navigation

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.

Sun Mon Tue Wed Thu Fri Sat
- 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 -
- 12:00 – 16:00 12:00 – 16:00 12:00 – 16:00 12:00 – 16:00 12:00 – 16:00 -

Supporter timezone: Europe/Zagreb (GMT+01:00)

Tagged: 

This topic contains 1 reply, has 0 voices.

Last updated by Dražen 3 days, 3 hours ago.

Assisted by: Dražen.

Author Posts
January 23, 2025 at 8:06 am #16625880

danielI-23

Background of the issue:
I am trying to publish a post titled XYZ on site.com/news/xyz using a custom URL rewrite rule that adds /news/ to all my posts. When I upload a document named xyz.jpg to the media library, WordPress creates an attachment page at site.com/xyz. I don't mind these attachment pages, but when WPML is active, visiting site.com/news/xyz redirects me to site.com/xyz. I noticed a 301 request with a header 'X-Redirect-By: WPML' as seen here: hidden link.

Symptoms:
When WPML is active, visiting my post URL site.com/news/xyz redirects to the attachment page site.com/xyz. The issue is identified by a 301 redirect with 'X-Redirect-By: WPML'.

Questions:
Why is WPML redirecting my post URL to the attachment page URL?
How can I disable this redirect behavior?

January 23, 2025 at 12:14 pm #16627623

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+01:00)

Hello,

thanks for contacting us.

I checked further, and you forgot to mention posts are set as Not translatable. This seems to be a known bug and it is escalated to our developers but I think it is a low priority, and it will take some time before we have a permanent fix.

What I can suggest is to try the following:

1) Possible workaround:
go to: wp-content/plugins/sitepress-multilingual-cms/classes/query-filtering/class-wpml-404-guess.php
adjust the method: \WPML_404_Guess::order_by_type_and_language_snippet
Change from:

			$order_by .= ' , ' . $this->order_by_post_type_snippet();

to:

$post_order = $this->order_by_post_type_snippet();
			$orderclone = $order_by;
			$order_by = $post_order . ' , ' . $orderclone;

Of course, this may break the translations in the end, please test it on the staging site.

2) Setting the post to be translatable.

3) Using different names / slugs for post and images, to avoid such issue.

Hope this helps.

Regards,
Drazen