Woocommerce 是否删除重复的分类法页面链接?

Woocommerce 是否删除重复的分类法页面链接?,woocommerce,duplicates,taxonomy,Woocommerce,Duplicates,Taxonomy,我有一个问题,重复的内容,这似乎是一个开箱即用的问题与woocommerce。例如,我们的SEO公司抱怨内容重复,因为您可以访问: http://localhost/wp7/product-category/clothing/hoodies/ 但是你也可以去 http://localhost/wp7/product-category/hoodies/ 因此,衣服是连帽衫的父分类法。是否有一个过滤器/代码使您无法导航到仅子分类链接,而只允许http://www.example.com/prod

我有一个问题,重复的内容,这似乎是一个开箱即用的问题与woocommerce。例如,我们的SEO公司抱怨内容重复,因为您可以访问:

http://localhost/wp7/product-category/clothing/hoodies/
但是你也可以去

http://localhost/wp7/product-category/hoodies/
因此,
衣服
连帽衫
的父分类法。是否有一个过滤器/代码使您无法导航到仅子分类链接,而只允许
http://www.example.com/product-category/parent/child

在此方面的任何帮助都将不胜感激


亲切的问候,谢谢

我用这个解决方案解决了这个问题。它似乎工作得很好。不确定在woocommerce生态系统中的影响,但它肯定在前端起作用

/**
 * Disallow duplicate Woocommerce taxonomy links
 * |- Redirects http://www.example.com/product_cat/child to http://www.example.com/product_cat/parent/child
 */
add_action('template_redirect', function ($query) {
    global $wp;
    $productCatTaxonomy = 'product_cat';

    if (is_tax($productCatTaxonomy)) {
        $current_url = add_query_arg($wp->query_string, '', home_url($wp->request));
        $current_args = parse_url($current_url);
        $currentTerm = get_term_by('slug', get_query_var('term'), $productCatTaxonomy);

        if (isset($current_args['query']) && !stristr($current_args['query'], '%2f')) {
            $currentParentTerm = (isset($currentTerm->parent) && $currentTerm->term_id) ? get_term_by('id', $currentTerm->parent, $productCatTaxonomy) : 0;

            if ($currentParentTerm) {
                $childTermLink = (isset($currentTerm->term_id) && $currentTerm->term_id) ? get_term_link($currentTerm->term_id, $productCatTaxonomy) : 0;

                if ($childTermLink) {
                    wp_redirect($childTermLink);
                    die();
                }
            }
        }
    }

    return $query;
});