Skip Navigation

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

Problem:
The client is using Elementor and WooCommerce to display carousels with links to product attributes (brands) that are set to 'not translatable'. The links should link to the current language version, but WPML is altering them to the default language. The client wants these specific links to remain unchanged in the translated pages.
Solution:
We recommended adding a custom filter to the theme's functions.php file to prevent WPML from altering these specific links. Here is the code snippet to add:

add_filter('wpml_sl_blacklist_requests', 'wpml_sl_blacklist_requests', 10, 2);<br />function wpml_sl_blacklist_requests($blacklist, $sitepress) {<br />    $blacklist[] = 'brand/nike-sb';<br />    return $blacklist;<br />}

This code will add the specified brand to a blacklist, preventing WPML from translating the URL. For more information on managing sticky links in WPML, visit WPML Sticky Links documentation.

If this solution does not apply to your case, or if it seems outdated, 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 issues persist, 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 0 reply, has 1 voice.

Last updated by Dražen 3 months, 2 weeks ago.

Assisted by: Dražen.

Author Posts
February 20, 2025 at 3:15 pm #16730468

amigosS

Hello and wow thank you so much ! It works on the production website too.

One question though, is there a way to make it work for all brand attributes without having to write them all (and since we can create new ones, the idea would be to not have to edit this code every time).

Again, thank you so much !

February 20, 2025 at 3:20 pm #16730502

Dražen
Supporter

Languages: English (English )

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

Hello,

great, glad to hear that.

I am afraid not, in this situation, you would need to add these but maybe you can automate this with additional code, like to get pages under brands/.. and add them to $blacklist[] etc.

Regards,
Drazen

February 20, 2025 at 3:30 pm #16730519

amigosS

Oh ok, would a regex work in this situation ?
If not, I'll write something to add all pa_brand attributes into the array.

February 20, 2025 at 3:35 pm #16730544

Dražen
Supporter

Languages: English (English )

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

Hello,

to be fair, I am not sure, it is a bit out of my knowledge. If you need help with custom coding you can use the service of WPML Contractors:

- https://wpml.org/contractors/

Hope that helps.

Regards,
Drazen

February 20, 2025 at 3:38 pm #16730566

amigosS

Yeah, no worries, it's ok I figured something out.
If anyone needs it :

///
function wpml_sl_blacklist_requests( $blacklist, $sitepress ) {
$brands = get_terms( [
'taxonomy' => 'pa_brand', // or whatever taxonomy you're using
'hide_empty' => false,
] );

if ( ! is_wp_error( $brands ) && ! empty( $brands ) ) {
foreach ( $brands as $brand ) {
$blacklist[] = 'brand/' . $brand->slug; // change the 'brand' slug if needed
}
}

return $blacklist;
}

add_filter( 'wpml_sl_blacklist_requests', 'wpml_sl_blacklist_requests', 10, 2 );
///

Thank you for you help !

February 20, 2025 at 4:06 pm #16730646

Dražen
Supporter

Languages: English (English )

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

Hello,

great, thanks for sharing it!

I will be closing the ticket now, hope that is okay.

Kind regards,
Drazen