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 |
---|---|---|---|---|---|---|
- | - | 9:00 – 18:00 | 9:00 – 18:00 | 9:00 – 18:00 | 9:00 – 18:00 | 9:00 – 18:00 |
- | - | - | - | - | - | - |
Supporter timezone: America/Lima (GMT-05:00)
Tagged: Compatibility, Documentation request
This topic contains 19 replies, has 1 voice.
Last updated by Andreas W. 22 hours, 25 minutes ago.
Assisted by: Andreas W..
Author | Posts |
---|---|
March 22, 2025 at 4:51 pm #16847837 | |
alexZ-17 |
Background of the issue: Symptoms: Questions: |
March 22, 2025 at 8:51 pm #16847986 | |
Andreas W. Supporter Languages: English (English ) Spanish (Español ) German (Deutsch ) Timezone: America/Lima (GMT-05:00) |
Hello, The image meta information is not part of the WP Carousel. In such case, you need to translate the meta information directly inside the media library while switching the admin language to the second language and editing the media. If you do not find the media in a second language you will first need to run the dialog to sync media at WPML > Settings > Media Translation by clicking the "Start" button. If this will not solve the issue, please let us know. Best regards |
March 23, 2025 at 1:40 pm #16848707 | |
alexZ-17 |
Hello, |
March 25, 2025 at 12:36 pm #16857577 | |
Otto Supporter
Languages: English (English ) Spanish (Español ) Timezone: America/Argentina/Buenos_Aires (GMT-03:00) |
Hello, I apologize for the delay in answering. I will take care of this ticket and reply time will be shorter now. To ensure the quickest and most accurate support, please provide your debug information so I can look at some of your configurations. We have an excellent article on how to locate it here: https://wpml.org/faq/provide-debug-information-faster-support/. WP Carousel is not in our compatibility list, however, it doesn't necessarily imply that it is not compatible, just that our team has not tested it yet. Which version are you using? Free or PRO? The author claims that the PRO version is compatible with WPML: I suggest checking with their support, too. With your response, we will move forward. Best Regards, |
March 28, 2025 at 1:21 pm #16873135 | |
alexZ-17 |
I use the free version |
March 28, 2025 at 1:25 pm #16873146 | |
Otto Supporter
Languages: English (English ) Spanish (Español ) Timezone: America/Argentina/Buenos_Aires (GMT-03:00) |
Hello, You should check with them if the free version is compatible. On our end, we have tested these alternatives for the carousel feature: Best Regards, |
March 28, 2025 at 1:29 pm #16873150 | |
alexZ-17 |
have you checked the debug information provided by me? |
March 28, 2025 at 1:35 pm #16873172 | |
Otto Supporter
Languages: English (English ) Spanish (Español ) Timezone: America/Argentina/Buenos_Aires (GMT-03:00) |
Yes, I did. I didn't note anything off there. It helps us to detect memory issues or outdated plugins, for example. But it looks OK in this case. Best Regards, |
March 28, 2025 at 2:00 pm #16873366 | |
alexZ-17 |
I am dissapointed by your formal approach to my problem. |
March 28, 2025 at 5:39 pm #16874210 | |
Andreas W. Supporter Languages: English (English ) Spanish (Español ) German (Deutsch ) Timezone: America/Lima (GMT-05:00) |
I was able to replicate the issue on a test site. General workflow: The shortcode to display a WP Carousel looks like this: This means that each carousel in each language has a unique shortcode. You need to make the WP Carousel post type inside WPML's setting "Translatable", then translate the carousel and make sure that you use the correct shortcode on each page. Go to WPML > Settings > Post Type Translation and set "All Carousels (sp_wp_carousel)" to "Translatable only show translated items". Then go to WPML > Settings > Custom Field Translation and make sure that the following fields are set to "Copy": sp_wpcp_shortcode_options Now go to WP Carousel > All Carousell and translate the carousel using the WPML Translation Editor. Back on the list, switch the admin language to German. You will now realize that the German carousel uses a different shortcode. You might need to paste those shortcodes manually on each page. Issue: Investigating this further, it looks like the WP Carousel post type is not getting the translations from the media library. Even if I try to edit the media information directly on the translated carousel inside the WordPress Editor, we still see the original meta information on the translated carousel. The issue seems to be in how the carousel is being rendered on the Frontend. To fix the issue, we will need the cooperation of the plugin's author. Open the file Replace the following function: public static function get_item_image( $lazy_load_image, $wpcp_layout, $img_url, $title_attr, $width, $height, $alt_text, $lazy_img_url ) { if ( 'false' !== $lazy_load_image && 'carousel' === $wpcp_layout || 'slider' === $wpcp_layout ) { $image = sprintf( '<img class="wcp-lazy swiper-lazy" data-src="%1$s" src="%6$s" %2$s alt="%3$s" width="%4$s" height="%5$s">', $img_url, $title_attr, $alt_text, $width, $height, $lazy_img_url ); } else { $image = sprintf( '<img class="skip-lazy" src="%1$s"%2$s alt="%3$s" width="%4$s" height="%5$s">', $img_url, $title_attr, $alt_text, $width, $height ); } return $image; } with this new function: public static function get_item_image( $lazy_load_image, $wpcp_layout, $img_url, $title_attr, $width, $height, $alt_text, $lazy_img_url ) { // Use wpml_current_language filter to get the current language in WPML $current_language = apply_filters( 'wpml_current_language', null ); // Get current language // Ensure that WPML is active and the current language is set if ( class_exists( 'SitePress' ) && $current_language ) { // Get the attachment ID from the image URL (assuming $img_url is the image URL) $attachment_id = self::get_attachment_id_from_url( $img_url ); if ( $attachment_id ) { // Get the translated alt text using the attachment ID $alt_text = self::get_translated_alt_text( $attachment_id, $current_language ); } } // Construct the image tag depending on the layout and lazy load if ( 'false' !== $lazy_load_image && ( 'carousel' === $wpcp_layout || 'slider' === $wpcp_layout ) ) { // Lazy-loaded image $image = sprintf( '<img class="wcp-lazy swiper-lazy" data-src="%1$s" src="%6$s" %2$s alt="%3$s" width="%4$s" height="%5$s">', $img_url, $title_attr, $alt_text, $width, $height, $lazy_img_url ); } else { // Regular image without lazy loading $image = sprintf( '<img class="skip-lazy" src="%1$s" %2$s alt="%3$s" width="%4$s" height="%5$s">', $img_url, $title_attr, $alt_text, $width, $height ); } return $image; } // Method to retrieve translated alt text based on the attachment ID and current language private static function get_translated_alt_text( $attachment_id, $current_language ) { // Ensure WPML is active and attachment ID exists if ( class_exists( 'SitePress' ) && $attachment_id ) { // Get the translated attachment using WPML's translation functionality $translated_attachment_id = apply_filters( 'wpml_object_id', $attachment_id, 'attachment', false, $current_language ); // If a translated attachment is found, get the alt text from the translated post meta if ( $translated_attachment_id ) { // Get the translated alt text from the media attachment $translated_alt = get_post_meta( $translated_attachment_id, '_wp_attachment_image_alt', true ); if ( $translated_alt ) { return $translated_alt; // Return the translated alt text } } } // Fallback to the original alt text if no translation is available return get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ); // Fallback to the original alt } // Helper function to get attachment ID from URL (example) private static function get_attachment_id_from_url( $image_url ) { global $wpdb; // Retrieve the attachment ID from the image URL by querying the postmeta table $attachment_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND meta_value LIKE %s", '%' . $wpdb->esc_like( basename( $image_url ) ) . '%' ) ); return $attachment_id; } The old function was using $alt_text directly without linking it to a specific attachment ID. WPML stores translations for media items based on the attachment ID. Since the img_url is the same across languages, there was no way for the function to fetch the correct translated alt text without considering the attachment ID. The new function will make sure that we obtain the information for the correct attachment. This solved the issue on my test. I am now escalating this issue to our compatibility team, but please take note once more, that this problem will only be solved, if the author of WP Carousel adapts the code of the plugin to achieve compatibility with WPML. |
March 29, 2025 at 7:00 am #16874917 | |
alexZ-17 |
Thank you for the prompt reply. |
March 29, 2025 at 2:02 pm #16875402 | |
Andreas W. Supporter Languages: English (English ) Spanish (Español ) German (Deutsch ) Timezone: America/Lima (GMT-05:00) |
My apologies for forgetting to mention the file name. The file is wp-content\plugins\wp-carousel-free\public\WPCF_Helper.php I would suggest you report this to the author and ask if they would consider making the plugin compatible with WPML. |
March 29, 2025 at 3:16 pm #16875461 | |
alexZ-17 |
Ok, then I do the following: |
March 29, 2025 at 3:40 pm #16875492 | |
Andreas W. Supporter Languages: English (English ) Spanish (Español ) German (Deutsch ) Timezone: America/Lima (GMT-05:00) |
You can use the provided workaround and it will solve the issue. If the author is willing to implement this change does sadly not depend on us. It seems the PRO version supports WPML: Could you please ask them for confirmation? |
March 29, 2025 at 4:17 pm #16875532 | |
alexZ-17 |
Request to ShapedPlugin sent: |