WordPress.org

Ready to get started?Download WordPress

Forums

WordPress SEO by Yoast
Suggestion: Remove canonical per post or page (9 posts)

  1. gerobe
    Member
    Posted 2 years ago #

    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?

    http://wordpress.org/extend/plugins/wordpress-seo/

  2. diesel12
    Member
    Posted 2 years ago #

    Agreed!

  3. akamust
    Member
    Posted 2 years ago #

    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...

  4. akamust
    Member
    Posted 2 years ago #

    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 ;)

    thanks

  5. gerobe
    Member
    Posted 2 years ago #

    @akamust
    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?

  6. akamust
    Member
    Posted 2 years ago #

  7. gerobe
    Member
    Posted 2 years ago #

    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' );
  8. akamust
    Member
    Posted 2 years ago #

    yup :)

  9. roundaboutmv
    Member
    Posted 1 year ago #

    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' );

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic