Support » Plugin: Yoast SEO » [Plugin: WordPress SEO by Yoast] Suggestion: Remove canonical per post or page

  • Hello,

    it would be great to have the possibility to disable the canonical-tag per post or page. Right now, you can only change it.

    I’m e.g using a special page template that displays different content based on certain parameters which are added to the post-slug like subfolders. But right now WordPress SEO adds always the same canonical entry. So the best solution would be do disable the canonical-tag completely.

    I’m doing this right now be changing line 412 of class-frontend.php into

    if ( ($canonical && !is_wp_error( $canonical )) && !stristr($canonical, '/slug_of_page/') ) {

    Having the possibility to remove the canonical entry for a page in the page’s seo setting would be great.

    This might also be useful for other occasions.

    What do you think?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Agreed!

    totally agree.

    for example, Simple:Press plugin already add its canonical and it’s correct, while WordPress SEO displays as canonical the URL of the page used to display the forum.

    having the possibility of removing the canonical on that page would allow the simple:press canonical to be the only (and correct) one on every forum page…

    update: Joost (the author of this great plugin) answered in no time on twitter to my question about this issue.

    solution is: just return false on the wpseo_canonical filter.

    posting here for others 😉


    Thank you for the investigation.
    What does it mean to “return false on the wpseo_canonical filter”?
    What do I have to do where to do this?

    I see, it’s more a theoretical solution so far 🙂

    So let’s be more precise. Will this code work in functions.php if the page-number is 4350?

    function wpseo_canonical_exclude( $canonical ) {
    		global $post;
    		if ( $post->ID == 4350) {
        		$canonical = false;
    	return $canonical;
    add_filter( 'wpseo_canonical', 'wpseo_canonical_exclude' );

    yup 🙂

    gerobe’s solution below worked great for me to exclude the canonical for one page. My question is, what is the correct syntax to have it excluded on two pages? I’m assuming there’s might be “array” involved, but so far everything I’ve tried has broken it.

    of function wpseo_canonical_exclude( $canonical ) {
    global $post;
    if ( $post->ID == xxx) {
    $canonical = false;
    return $canonical;
    add_filter( ‘wpseo_canonical’, ‘wpseo_canonical_exclude’ );

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Plugin: WordPress SEO by Yoast] Suggestion: Remove canonical per post or page’ is closed to new replies.