ナビゲーションをスキップする

Open

Topic Tags: Compatibility

Overview of the issue

When using Elementor Pro’s Loop Grid with alternate templates, non-dynamic content translated within the loop template does not appear in the correct language on the frontend. This issue occurs because the alternate template IDs are not translated.

Workaround

Please, make sure of having a full backup of your site before proceeding.

  • Open your theme’s functions.php file.
  • Add the following code:
    // WPML Workaround for compsupp-6865
    add_filter('elementor/frontend/before_render', 'wpml_compsupp6865_filter_loop_grid_widget');
    
    function wpml_compsupp6865_filter_loop_grid_widget($element) {
        if ('loop-grid' !== $element->get_name()) {
            return $element;
        }
    
        $settings = $element->get_settings();
    
        if (!isset($settings['alternate_templates']) || !is_array($settings['alternate_templates'])) {
            return $element;
        }
    
        $alternate_settings = $settings['alternate_templates'];
    
        foreach ($alternate_settings as $key => $value) {
            if (empty($value['template_id']) || !is_numeric($value['template_id'])) {
                continue;
            }
    
            // Use apply_filters to adjust template_id for WPML
            $id = apply_filters('wpml_object_id', $value['template_id'], get_post_type($value['template_id']), true);
            if (!is_numeric($id)) {
                continue;
            }
    
            // Update the template_id in alternate_settings
            $alternate_settings[$key]['template_id'] = $id;
        }
    
        // Update the settings with the modified alternate_templates
        $settings['alternate_templates'] = $alternate_settings;
        $element->set_settings('alternate_templates', $settings['alternate_templates']);
    }
    

返答する

トピックからそれないようにし、他のユーザーを尊重してください。この投稿に関係のない問題についてサポートが必要な場合は、サポート フォーラムを使用してチャットを開始するか、チケットを送信してください。

これらのタグを使用できます:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>