Skip to content

Instantly share code, notes, and snippets.

@Xyborg
Last active August 29, 2015 14:14
Show Gist options
  • Save Xyborg/b55826218ac8ff5bf01b to your computer and use it in GitHub Desktop.
Save Xyborg/b55826218ac8ff5bf01b to your computer and use it in GitHub Desktop.
SEO by Yoast: Exclude URLs from canonical
/* Add this function to the functions.php in your theme folder */
/* to exclude certain posts from url canonicalization of SEO by Yoast plugin */
function wpseo_canonical_exclude( $canonical ) {
global $post;
if ( get_post_type( get_the_ID() ) == "name_your_post_type") {
//if ( $post->ID == 7777) {
$canonical = false;
}
return $canonical;
}
add_filter( 'wpseo_canonical', 'wpseo_canonical_exclude' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment