WPML
상태
해결됨
보고된 제품
WPML Multilingual CMS 4.6.15
해결된 버전
WPML 4.7.5
관련 플러그인/테마
Elementor
주제 태그
Compatibility

문제 개요

Elementor의 이미지 위젯을 사용할 때, 번역된 페이지가 여전히 원본 언어의 이미지를 참조하여 보조 언어에서 잘못된 ALT 텍스트가 표시될 수 있습니다.

임시 해결 방법

진행하기 전에 반드시 전체 사이트 백업을 수행하세요.


  • 테마의 functions.php 파일을 여세요.

  • 다음 스니펫을 추가하세요:
    // WPML: Find translatable IDs in Elementor Widgets
    add_filter( 'elementor/frontend/before_render', 'wpml_compsupp_find_translatable_post_ids_in_settings' );
    
    function wpml_compsupp_find_translatable_post_ids_in_settings( $element ) {
    
        $widget_name = $element->get_name();
        $settings    = $element->get_settings();
    
        // Recursively translate post IDs in settings array
        $translated_settings = wpml_compsupp_find_translatable_post_ids_in_array( $settings, $widget_name );
    
        $element->set_settings( $translated_settings );
    }
    
    function wpml_compsupp_find_translatable_post_ids_in_array( $settings, $widget_name, $path = [] ) {
    
        $apply_translations = true; // if set to false, translated IDs are not applied to the content
    
        foreach ( $settings as $key => &$value ) {
            // Translate IDs and handle nested settings
            $currentPath = array_merge($path, [$key]);
    
            if ( is_array( $value ) || is_object( $value ) ) {
                // If the value is an array or object, run the function recursively
                $value = wpml_compsupp_find_translatable_post_ids_in_array((array)$value, $widget_name, $currentPath);
            } elseif ( is_numeric( $value ) && $value != 0 ) {
                // Translate post ID if it is numeric and a valid post type exists
                $post_type   = get_post_type( $value );
                $post_status = get_post_status( $value );
    
                if ( $post_type && $post_status == 'publish' ) {
                    $translated_value = apply_filters( 'wpml_object_id', $value, $post_type, true );
    
                    if ($apply_translations === true ) {
                        $value = $translated_value;
                    }
                }
            }
        }
    
        return $settings;
    }

알려진 모든 문제 →