Search code examples
filtercanonical-linkyoast

Removing rel canonical added by Yoast SEO plugin from filter pages


I do Use filter plugin that generate get parameters like this https://example.com/product-category/mobile-phone/?product_brand=sony

and yoast plugin removes all the parameters after the "?" by "rel canonical" tag and it makes it like this:

<link rel="canonical" href="https://example.com/product-category/mobile-phone/" />

1- i need a function to disable canonical from "?" parameters.

yoast already introduced a lot of "remove functions" but not like this


Solution

  • Use this code:

    function yoast_seo_canonical_change_product_category( $canonical ) { 
    
        if ( is_product_category() ) {      
            $canonical = false;
        }
    
        return $canonical;
    }
    
    add_filter( 'wpseo_canonical', 'yoast_seo_canonical_change_product_category', 99, 1 );