Home›Support›English Support›[Resolved] Translated URL structure appearing differently in different locations
[Resolved] Translated URL structure appearing differently in different locations
This thread is resolved. Here is a description of the problem and solution.
Problem: If you're experiencing issues with the primary category not being correctly represented in the Language Switcher for Spanish URLs, leading to incorrect URL structures on page load, particularly after updating to version 4.7.4, this might be due to a compatibility issue with the Only Top Category option of the Grid Post widget from the Unlimited Elements for Elementor (Premium) plugin.
Solution: First, we recommend replicating the issue on a clean installation to confirm it's a compatibility issue. Here are the steps: 1. Install Unlimited Elements for Elementor (Premium) on a clean WordPress installation with Elementor, Yoast, WPML, and all necessary WPML add-ons. 2. Create the same situation and try to replicate the issue.
Additionally, there is a workaround provided by our compatibility team: 1. Open the file
function on line 574. 3. Replace the existing code with the new code provided, which includes a WPML filter to ensure the primary category ID is correctly translated. 4. Clear Elementor's cache by going to "Elementor > Tools > Clear Files & Data" and ensure the translation is 100% complete.
If these steps do not resolve your issue, or if the solution seems outdated or irrelevant 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 problem persists, please open a new support ticket at WPML support forum for further assistance.
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.
Background of the issue:
I am trying to achieve consistency in URL structure display across my site.
I updated to 4.7.4 in the last 2 weeks and have just now noticed an issue when adding new Blog Posts and translating.
English is the Primary language.
Problem occurs to the Spanish URLs ONLY (issue does not occur in IT, FR or DE). When translating the posts, the Spanish URL structure translates (and appears) correctly in WordPress Editor.
Example URL in EN: hidden link.
If you view it on a Post Grid/Category page e.g. - hidden link, it displays as above in EN - correctly.
Switch to Post Grid/Category page to Spanish - hover over the Post and the URL in Spanish it displays correctly: hidden link. Problem:
Go back a step to - hidden link.
Open/Click on the EN post - hidden link.
Hover/Click on the Language Switcher - Spanish.
This is the result: hidden link.
However it should be: hidden link.
Categories Selected in the Editor: turistas-de-cruceros/ - is the Yoast Primary category and is selected in WP Editor and translates through all languages correctly.
moverse-por-la-spezia/ - is also a category selected and translated correctly, however is replacing the primary category in some situations.
Consejos-de-viaje/ - another category assigned to the post (not appearing anywhere as it shouldn't).
So the last couple NEW Posts created and translated - the primary Category is not correctly represented in the Lang Switcher, and therefore on page load.
Categories are Synced in WPML Taxonomy Translation.
It does seem to be correct everywhere else.
This is not happening to any of our other post types at present.
Symptoms:
The primary category is not correctly represented in the Language Switcher for Spanish URLs, leading to incorrect URL structures on page load.
Questions:
Why is the primary category not correctly represented in the Language Switcher for Spanish URLs?
How can I ensure the correct URL structure is displayed for Spanish translations?
Welcome to WPML support. Please get back to us with the result of the:
1. Clean installation of WordPress, check for the Ultimate Elementor addon for the grid options to test the inconsistent categories of the Italian version.
2. Check for possible plugins and theme conflicts for the unusual redirection issue for the Spanish version:
The issue I would really like to address and solve is the Spanish URL appearing with a completely different category in the URL ONLY IN THE LANGUAGE SWITCHER, as this is a problem that has only recently arisen.
The URL created and that appears in the Unlimited Elements post grid is with the correct category (again, just the language switcher displays a different category in the URL).
It is not a redirect issue, it is choosing to display another Category (albeit it is one of the other categories selected in WordPress Edit Post - but just not the Primary one). The Primary Category has always been the one to appear in the URL for all posts in all languages until the last 2 posts - but again only in Spanish the rest are appearing as they should.
Is it possible to focus on fixing this first?
The Post Grid issue is something I can live with for now - but am happy to also add to the sandbox if you want to test for compatibility.
Sure for that we will indeed need you to provide us with a staging / copy version of the website so we can do troubleshooting.
The first step would be to check if the same thing happens on a minimal installation or not, according to the steps given in the chat.
You can set the next reply to provide us with the staging version of the website so we can do troubleshooting without the fear of ruining a live website.
Thank you for the info. I managed to access the website and after troubleshooting it seems to be a compatibility issue between the Only Top Category option of the Grid Post widget of the Unlimited Elements for Elementor (Premium) plugin.
I created a video explaining why that is what I concluded:
hidden link
To be able to report the compatibility issues we need to replicate the issue on a clean installation.
I created a clean installation of WordPress, Elementor, Yoast, WPML, and all necessary WPML add-ons.
You can access the WordPress dashboard using the link below:
hidden link
Kindly follow the steps below:
- Install Unlimited Elements for Elementor (Premium).
- Create the same situation.
- Try to replicate the issue.
This will help us to report the probable issue to the compatibility team and solve the possible problem faster.
I also suggest that you contact the plugin developers and report the issue.
3 Posts - Set the primary category and selected an additional category
Added some categories
Added the Post Grid Unlimited Elements Widget - configured it a little to display a few items, including Categories
Translated in the ATE also translated the Taxonomies in the ATE (normally one would do it in Taxonomies Translations but it appeared in the ATE so I translated them there).
The issue still happens in this clean installation.
it appears to ignore the primary category and display the category in preference of alphabetical order hence you will notice on the 3rd post red changed to Black when switching to FR.
Also, if you set the primary category to Green instead of Blue (in English) for the middle post you will see it change also.
There is a workaround suggested below by the compatibility team:
- Open the .../wp-content7plugins7unlimited-elements-for-elementor7provider7provider_params_processor.class.php file
- Look for the getPostMainCategory function on line 574
- Replace:
/**
* get post main category from the list of terms
*/
private function getPostMainCategory($arrTerms, $postID){
//get term data
if(count($arrTerms) == 1){ //single
$arrTermData = UniteFunctionsUC::getArrFirstValue($arrTerms);
return($arrTermData);
}
$arrMeta = UniteFunctionsWPUC::getPostMeta($postID,true);
$mainCategoryID = UniteFunctionsUC::getVal($arrMeta, "_yoast_wpseo_primary_category");
if(empty($mainCategoryID))
$mainCategoryID = UniteFunctionsUC::getVal($arrMeta, "rank_math_primary_category");
if(empty($mainCategoryID)){
unset($arrTerms["uncategorized"]);
$arrTermData = UniteFunctionsUC::getArrFirstValue($arrTerms);
return($arrTermData);
}
- With:
/**
* get post main category from the list of terms
*/
private function getPostMainCategory($arrTerms, $postID){
//get term data
if(count($arrTerms) == 1){ //single
$arrTermData = UniteFunctionsUC::getArrFirstValue($arrTerms);
return($arrTermData);
}
$arrMeta = UniteFunctionsWPUC::getPostMeta($postID,true);
$mainCategoryID = UniteFunctionsUC::getVal($arrMeta, "_yoast_wpseo_primary_category");
if(empty($mainCategoryID))
$mainCategoryID = UniteFunctionsUC::getVal($arrMeta, "rank_math_primary_category");
// WPML Workaround for compsupp-8023
if (!empty($mainCategoryID)) {
$mainCategoryID = apply_filters('wpml_object_id', $mainCategoryID, 'category', true);
}
if(empty($mainCategoryID)){
unset($arrTerms["uncategorized"]);
$arrTermData = UniteFunctionsUC::getArrFirstValue($arrTerms);
return($arrTermData);
}
- Go to Elementor's cache in "Elementor > Tools > Clear Files & Data and clear Elementor Cache
- Do a small change on the original page
- Make sure the translation is 100% complete.
Ok sure, that is correct, if the plugin is updated it will be overwritten. We need your confirmation first and then we will contact the developers of the plugin and inform them about the issue.
After that, it is up to them to implement a solution. It might not necessarily be a solution like ours as they might have other considerations regarding their codebase.
That seemed to work just fine, i did not even need to do a post/page update and translation - the Categories automatically updated on refresh and now match for all languages.
So i can confirm after checking many pages/posts all is now working with your workaround.
I will get in touch with Unlimited Elements and let them know also.
Thanks for your help with all this.
Manage Cookie Consent
We use cookies to optimize our website and services. Your consent allows us to process data such as browsing behavior. Not consenting may affect some features.
Functional
Always active
Required for our website to operate and communicate correctly.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
We use these to analyze the statistics of our site. Collected information is completely anonymous.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
These cookies track your browsing to provide ads relevant to you.