Skip to content

Instantly share code, notes, and snippets.

@aahan
Created November 13, 2013 13:36
Show Gist options
  • Save aahan/7449233 to your computer and use it in GitHub Desktop.
Save aahan/7449233 to your computer and use it in GitHub Desktop.
WordPress SEO by Yoast filters
<?php
// Remove Canonical Link Added By Yoast WordPress SEO Plugin
function at_remove_dup_canonical_link() {
return false;
}
add_filter( 'wpseo_canonical', 'at_remove_dup_canonical_link' );
function wpseo_attachment_canonical_parent( $canonical ) {
if ( is_attachment() ) {
global $post;
$attachment = get_post( $post->ID );
$parent_post_id = $attachment->post_parent;
$canonical = get_permalink( $parent_post_id );
}
return $canonical;
}
add_filter( 'wpseo_canonical', 'wpseo_attachment_canonical_parent' );
function wpseo_canonical_exclude( $canonical ) {
global $post;
if ( $post->ID == 4350) {
$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