Filter for overriding canonical URLs?
-
Hi!
I am switching from Yoast to The SEO Framework on a site, but I have a function that I’m not sure how to replicate.
Here is the function:
function rel_canonical_with_custom_tag_override($canonical) { global $post; if( is_singular() ) { $canonicalProduct = get_field('master_product', $post->ID); if( $canonicalProduct && '' != $canonicalProduct ) { return get_the_permalink($canonicalProduct); } } return $canonical; } add_filter( 'wpseo_canonical', 'rel_canonical_with_custom_tag_override' );
Basically it checks to see if the product is a singular product, and it has a custom field of “Master Product”, then it changes the canonical URL to point to that product.
This is for preventing Google from seeing products that just contain slight differences as duplicate content.
It works with Yoast, is there a similar filter I can use?
Thanks!
Shaun
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Filter for overriding canonical URLs?’ is closed to new replies.