Skip to content Skip to sidebar

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

Problem:
The client is experiencing compatibility issues between The Events Calendar and WPML.

Solution:
We recommend adding the following code to your

functions.php

file:

/*<br />* WPML Workaround for compsupp-6815 (updated version for compsupp-7184)<br />*/<br />add_filter( 'tribe_rewrite_canonical_url', 'wpml_compsupp6815_resolve_missing_urls', 10, 3 );<br /><br />function wpml_compsupp6815_resolve_missing_urls( $resolved, $url, $object ) {<br /><br />    if ( class_exists('Sitepress') ) {<br />        $wpml_default_lang = apply_filters('wpml_default_language', NULL );<br />        $wpml_current_lang = apply_filters( 'wpml_current_language', NULL );<br />         <br />        // Let's register the calendar strings so we can translate and use in the workaround<br />        if ($wpml_default_lang == $wpml_current_lang ) {<br /><br />            $tec_options = get_option('tribe_events_calendar_options'); <br />            $events_slug = $tec_options['eventsSlug'];  <br />            $single_events_slug = $tec_options['singleEventSlug']; <br />                   <br />            do_action( 'wpml_register_single_string', 'the-events-calendar', 'TEC Calendar Slugs: '.substr($events_slug, 0, 20), $events_slug);<br />            do_action( 'wpml_register_single_string', 'the-events-calendar', 'TEC Calendar Slugs: '.substr($single_events_slug, 0, 20), $single_events_slug );<br />             <br />            foreach ($tec_options['tribeEnableViews'] as $calendar_string) {<br />                do_action( 'wpml_register_single_string', 'the-events-calendar', 'TEC Calendar Slugs: '.substr($calendar_string, 0, 20), $calendar_string);<br />            }<br />        }<br /> <br />        // Check if the URL is not resolved yet. If not, we will resolve it with the translated strings<br />        if ( preg_match( '#\(/\?\:([^)]+)\)#',  $resolved ) ) {<br /> <br />            $resolved = preg_replace_callback( '#\(/\?\:([^)]+)\)#', function($matches) use ($url) {<br />                $options = explode('|', trim($matches[0], '/(?:)'));<br />                 <br />                $slug = $options[0];                    <br /> <br />                $translated_slug = apply_filters('wpml_translate_single_string', $slug , 'the-events-calendar', 'TEC Calendar Slugs: '.substr($slug, 0, 20) );<br /> <br />                // Only apply the translation if the string already exists in the URL. If not, replace with the original. This may avoid possible 404 errors<br />                if (in_array(strtolower($translated_slug), $options) && $translated_slug != '') {<br />                    $slug = $translated_slug;<br />                } <br /> <br />                return $slug;<br /> <br />            }, $resolved );<br /><br />            // Check if there are parameters in the final result and correct the first "&" to "?"<br />            if (strpos($resolved, '&') !== false && strpos($resolved, '?') === false) {<br />                $resolved = preg_replace('/&/', '?', $resolved, 1);<br />            }<br />        }<br />    }<br /> <br />    return $resolved;<br />}<br />

After adding the code, navigate to Settings > Permalinks and re-save the settings.

If this solution does not resolve your issue or seems irrelevant due to being outdated or not applicable to your case, we encourage you to open a new support ticket. We also 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.

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.

This topic contains 18 replies, has 2 voices.

Last updated by Bobby 1 year, 5 months ago.

Assisted by: Bobby.

Author Posts
February 17, 2024 at 8:55 am #15313484

arianeF-2

Hi Bobby,
many thanks for your answer.
I've updated the snippet in the funciton.php and then saved again the permalinks.
Now if I see, the URL are correct... but the "next events" buttons are still not working both on EN and DE.
You can try yourself hitting the butttons on the calendar in the homepage (I attach the images).
Please let me know if you have further ideas. Thanks

Screenshot 2024-02-17 at 09.51.41.png
Screenshot 2024-02-17 at 09.51.51.png
February 20, 2024 at 6:06 pm #15324368

Bobby
WPML Supporter since 04/2015

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Thank you for updating me!

Just to verify, are the next buttons not working after adding the workaround provided by us or were they already not working before it?

February 23, 2024 at 5:40 am #15336029

arianeF-2

Hi Bobby, thanks for your answer.
As written in the message dated JANUARY 10, 2024 AT 5:21 AM, the malfunction of the "Next Event" button was "the problem"... so yes, the problem has always been here....
Please contact me if you need further informations.
Thanks in advance!

Max

February 26, 2024 at 9:38 pm #15346579

Bobby
WPML Supporter since 04/2015

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hi Max,

When I test this on your site it is working OK at the moment. Please see the following screencast:

hidden link