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

问题概述

使用 Houzez 主题时,通过“媒体”部分添加的房产媒体图片在翻译后的房产页面上不显示翻译后的 ALT 文本。

临时解决方法

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


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

  • 添加以下代码片段:
    add_filter('get_post_metadata', 'wpml_compsupp7300_filter_fave_property_images', 10, 4);
    
    function wpml_compsupp7300_filter_fave_property_images($null, $object_id, $meta_key, $single) {
        
    	// Target the specific meta key
        if ($meta_key !== 'fave_property_images') {
            return $null;
        }
    
        // Prevent recursion by temporarily removing the filter
        remove_filter('get_post_metadata', 'wpml_compsupp7300_filter_fave_property_images', 10);
    
        // Fetch the original meta value
        $images = get_post_meta($object_id, $meta_key, $single);
    
        // Re-add the filter
        add_filter('get_post_metadata', 'wpml_compsupp7300_filter_fave_property_images', 10, 4);
    
        // Check if we actually got an array
        if (is_array($images)) {
            foreach ($images as &$image_id) {
                // Apply the WPML filter to each item (image ID)
                $image_id = apply_filters('wpml_object_id', $image_id, 'attachment', true);
            }
        }
    
        return $images;
    }

所有已知问题 →