WPML
状态
已由作者解决
相关插件/主题
CozyStay
主题标签
Compatibility

问题概述

CozyStay 主题中,使用 WPML 翻译图库图像的替代文本无法按预期工作。尽管通过高级翻译编辑器(ATE)翻译了替代文本,但翻译后的替代文本并未显示在已翻译页面的前端。

临时解决方法

在继续操作之前,请确保对您的站点进行完整站点备份


  • 打开您主题的 functions.php 文件。

  • 添加以下代码:
    // WPML Workaround for compsupp-7616
    add_filter('elementor/frontend/before_render', 'wpml_compsupp7616_filter_image_gallery_widget');
    
    function wpml_compsupp7616_filter_image_gallery_widget($element) {
    
        if ('cs_gallery' !== $element->get_name()) {
            return;
        }
    
        $settings = $element->get_settings();
    
        if (isset($settings['gallery']) && is_array($settings['gallery'])) {
            foreach ($settings['gallery'] as $key => $image) {
                if (isset($image['id'])) {
                    $post_type = get_post_type($image['id']);
    
                    if (!$post_type) {
                        continue;
                    }
    
                    $settings['gallery'][$key]['id'] = apply_filters('wpml_object_id', $image['id'], $post_type, true);
                }
            }
    
            $element->set_settings('gallery', $settings['gallery']);
        }
    }

所有已知问题 →