WPML

问题概述

在从产品类别手动编辑产品类别翻译时,即使仅更改了类别说明/文本(未更改别名),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 行左右找到它。
  • 将:
    PHP
    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 );
    }
  • 替换为:
    PHP
    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 '';
    }

所有已知问题

仍然遇到此问题?

如果更新无法解决问题,请提出支持问题,我们将与您一起排查。