WPML
状态
等待作者
相关插件/主题
Yoast SEO
主题标签
Compatibility

问题概述

在从“产品 > 类别”手动编辑产品类别翻译时,即使仅更改了类别说明/文本(未更改别名),Yoast SEO Premium 也会错误地创建 301 重定向。

创建的重定向包含格式错误的 URL:

旧 URL:http://site.com/product-category/test-es-wpml

新 URL:http://site.com/http://es.site.com/product-category/test-es-wpml/(双 URL!)

注意:这是一个视觉错误,这些重定向不会导致导航问题

临时解决方法

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


  • 打开 …/wp-content/plugins/wordpress-seo-premium/classes/term-watcher.php 文件。

  • 查找函数“protected function get_target_url(”,您会在第 241 行左右找到它。

  • 将:
    protected function get_target_url( $tag, $taxonomy ) {
        // Get the term link.
        $term_link = get_term_link( $tag, $taxonomy );
    
        // Return early if the term link is not a string, i.e. a WP_Error Object.
        if ( ! is_string( $term_link ) ) {
            return '';
        }
    
        return str_replace( home_url(), '', $term_link );
    }
            


  • 替换为:
    protected function get_target_url( $tag, $taxonomy ) {
        // Get the term link.
        $term_link = get_term_link( $tag, $taxonomy );
    
        // Return early if the term link is not a string, i.e. a WP_Error Object.
        if ( ! is_string( $term_link ) ) {
            return '';
        }
    
        // Extract the path to handle WPML subdomain URLs (matches post-watcher behavior).
        $url = wp_parse_url( $term_link );
        if ( is_array( $url ) && isset( $url['path'] ) ) {
            return $url['path'];
        }
    
        return '';
    }
            

所有已知问题 →