Forked from amboutwe/yoast_seo_canonical_change_woocom_shop.php
Created
September 28, 2017 21:22
-
-
Save jgresalfi/c2523e2d26862c50c9d97ea314b4d1b0 to your computer and use it in GitHub Desktop.
Code snippets for the Yoast SEO canonical output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/ | |
/* Remove Yoast SEO Canonical From All Pages | |
* Credit: Yoast Team | |
* Last Tested: Jun 16 2017 using Yoast SEO 4.9 on WordPress 4.8 | |
*/ | |
add_filter( 'wpseo_canonical', '__return_false' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/ | |
/* Remove Yoast SEO Canonical From Individual or Multiple Items | |
* Credit: Yoast Team | |
* Last Tested: Jun 16 2017 using Yoast SEO 4.9 on WordPress 4.8 | |
********* | |
* DIFFERENT POST TYPES | |
* Post: Change 123456 to the post ID | |
* Page: Change is_single to is_page and 123456 to the page ID | |
* Custom Post Type: Change is_single to is_singular and 123456 to the 'post_type_slug' | |
Example: is_singular( 'cpt_slug' ) | |
********* | |
* MULTIPLE ITEMS | |
* Multiple of the same type can use an array. | |
Example: is_single( array( 123456, 1234567, 12345678 ) ) | |
* Multiple of different types can repeat the if statement | |
*/ | |
add_filter( 'wpseo_canonical', 'yoast_remove_canonical_items' ); | |
function yoast_remove_canonical_items( $canonical ) { | |
if ( is_single ( 123456 ) ) { | |
return false; | |
} | |
/* Use a second if statement here when needed */ | |
return $canonical; /* Do not remove this line */ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/ | |
/* Remove Yoast SEO Canonical From Search Pages Only | |
* Credit: Yoast Team | |
* Last Tested: Jun 16 2017 using Yoast SEO 4.9 on WordPress 4.8 | |
*/ | |
add_filter( 'wpseo_canonical', 'yoast_remove_canonical_search' ); | |
function yoast_remove_canonical_search( $canonical ) { | |
if( is_search() ) { | |
return false; | |
} else { | |
return $canonical; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment