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.

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Waqar Ali 1 year ago.

Assisted by: Waqar Ali.

Author Posts
June 2, 2024 at 7:25 pm #15695893

karinaR

Hello,

I try to do generate links like this: /animal/SOMEANIMAL/product-category/SOMENAMECATEGORY

BUT - all my <a> tags are transformed to just /product-category/SOMECATEGORY and the animal part is just disappear.

And all works like expected when the WPML is off.

How to stop my structure links from filtering?

I tried to add debug info, but got the "*The debug information is not valid."
(I tried to past the text from the textarea at the wp-admin/admin.php?page=sitepress-multilingual-cms%2Fmenu%2Ftroubleshooting.php#wpml-settings)

June 3, 2024 at 7:05 am #15696422

Waqar Ali

Hi,

Thank you for contacting us and I'd be happy to assist.

To troubleshoot and suggest the next steps, I'll need to see how this permalink structure and WPML are configured on the website.

Can you please share temporary admin login details, along with the link to a page where such a link can be found?

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

regards,
Waqar

June 4, 2024 at 8:21 am #15700127

Waqar Ali

Thank you for sharing the access details.

I see that the links on those pages are getting generated through a custom shortcode 'custom_category_list_with_images' too.

Although 1-1 custom code assistance is beyond the scope of support that we provide over the forum, we do our best to guide in the right direction, whenever possible.

Do I have your permission to download a clone/snapshot of the website? This will help in testing this on a different server, without affecting the actual website.

June 4, 2024 at 9:17 am #15700627

karinaR

I give you permission, but highly recommend to skip the UPLOADS, as it almost 20 gb.

Yes, it is custom generated links, and they work like expected when the wpml is off. But when it is on, the code of the page or code of the <a> links if filtered somehow and they became modified. (It is easy to prove by turning off the main wpml plugin)

So I don't need assistance with custom code, it works.
I have a problem with filtering and modifying behavior of wpml plugin which is corrupted my links afterwards.

Thank you.

June 6, 2024 at 8:51 am #15709907

Waqar Ali

Just wanted to let you know that I'm currently running some tests on your website's clone.

I'll share the findings with you once this testing is completed.

Thank you for being so patient.

June 7, 2024 at 2:12 pm #15717068

Waqar Ali

Thank you for waiting.

During testing on your website's clone, I was able to exclude these custom links from WPML's filtering, using the following workaround:

1). In the active theme's 'functions.php' file, I updated the function 'build_pet_cat_link', so that instead of the 'href' it would include the target link in the 'data-link' attribute:
(note: I also included a class 'links-to-update' to distinguish these custom-generated links easily)

function build_pet_cat_link($slug, $pet) {
    $output = sprintf('<a href="#" data-link="/pets/%s/product-category/%s" class="links-to-update">', $pet, $slug);
    return $output;
}

2). Next, at the bottom of the same file, I also included the following function that would include a custom script in the footer across the website:

function build_pet_cat_link_script() {
    ?>
    <script type="text/javascript">
        jQuery( document ).on( 'ready', function( event, data ) {
            jQuery('a.links-to-update').each(function () {
                var url = jQuery(this).attr("data-link");
                if (url) {
                    jQuery(this).attr("href",url);
                }
            });
        });
    </script>
    <?php
}
add_action( 'wp_footer', 'build_pet_cat_link_script' );

This script finds all the links with the class 'links-to-update' and replaces the value from the 'data-link' attribute with the 'href' attribute, once the page loading has completed.

June 10, 2024 at 7:00 am #15720239

karinaR

Thank you, this workaround will fit to my needs.