How to disable the canonical url for a specific page when using Infinite SEO plugin?

I need to modify or remove the canonical url for specific pages.

The problem is the current canonical URL doesn't include the query string ?
So I need to remove this or modify it some how...

To clarify, say the canonical tag looks like this:
<link rel='canonical' target='_blank' href='' />

but I need it to be:
<link rel='canonical' target='_blank' href='' />

This of course matches the page URL:

For now, I am happy just to disable the function from infinite seo that is setting the canonical URL - but I don't know how..

The reason I need this is because it is preventing me from sharing these pages on facebook correctly as the set canonical url is incorrect.

If I deactivate the Infinite SEO plugin, I am able to share the page on facebook no problem as the canonical tag is no longer being used on this page. As I have disabled the wordpress canonical url for this specific page by adding the following code into my them functions.php file:
remove_action('wp_head', 'rel_canonical');

How do I do the equivalent when using the infinite seo plugin? I obviously want to use infinite SEO so deactivating it isn't an option.

Hoping this makes sense... Thanks for your help!

  • Vladislav
    • Dead Eye Dev


    Have you perhaps already checked the "Canonical" field in the "Infinite SEO" metabox in your editor - especially if it's just for a few pages, this might work well for this scenario and allow you to easily set the canonical the way you need it for those pages. Before going to the code-level solution, can we please give this a try since it's already built into the plugin and see if it helps?

  • SparkPlug
    • Site Builder, Child of Zeus

    Thanks Vladislav,

    Unfortunately that's not going to work as there are thousands of pages using this one page as the s_id=XX in the query string refers to different products and there are thousands of products.

    So basically, I just need something equivalent to:
    remove_action('wp_head', 'rel_canonical');

    but for the infinite SEO plugin.

    I realize that using a query string is not ideal but this is what I have to work with and it cannot be changed..

  • SparkPlug
    • Site Builder, Child of Zeus

    Thanks Ashok, any updates for this?

    I see that YOAST offers a similar SEO plugin that will allow me to do what I need using the following:

    add_filter( 'wpseo_canonical', '__return_false' );

    This is exactly what I need for the Infinite SEO plugin.

    I want to continue to use Infinite, I only post this here to help show what I need.


  • Ash
    • WordPress Hacker

    Hello @SparkPlug

    I am sorry for the delay. Vladislav is currently working on another internal project, that's why he is quite busy. But I am tagging him again.

    Also I am tagging an available developer from second level support line in this thread for his valuable opinion on this issue.


  • Jose
    • Bruno Diaz

    Hey @SparkPlug,

    I was struggling around this but I couldn't find a clean way to fix this yet. By a clean way, I mean to hook from outside the plugin without touching the core.

    If you don't mind hacking the plugin just a bit, then you can try one of the following solutions:

    To get rid of the canonical tag.
    Comment out the line 184 into the file ..\wp-content\plugins\wpmu-dev-seo\wds-files\wds-onpage\wds-onpage.php.
    It should look like this:

    function wds_head() {
    		global $wds_options;
    		global $wp_query, $paged;
    		$this->wds_stop_title_buffer(); // STOP processing the buffer.
    		$robots = '';
    		//$this->wds_canonical();//This is the line.

    But if you don't want to lose the canonical tag but still play well with facebook, you can include the query parameters into the canonical tag url.

    To add the query parameters.
    Change the line 223 in the same file to look as follows:

    ..if (is_singular()) {
                   echo "\t";
    	       //rel_canonical();//This is the original line.
                   // CUSTOM CODE START.
                   global $wp_the_query;
                   if ( !$id = $wp_the_query->get_queried_object_id() )
                   $link = get_permalink( $id ).'?'.$_SERVER['QUERY_STRING'];
                   if ( $page = get_query_var('cpage') )
                       $link = get_comments_pagenum_link( $page );
                   echo "<link rel='canonical' href='$link' />\n";
                   // CUSTOM CODE END.
    	} else {...

    Please let me know if this works for you. I can attach the modified file if you prefer, just let me know which option suits your needs better.


  • Vladislav
    • Dead Eye Dev


    Thank you @Jose for the code fix! Of course, as Jose said, editing the plugin file isn't really optimal solution, so the latest plugin release (v1.7.1, just released) comes with a different approach, that will allow you to achieve what you need it to without touching the core files. With the latest plugin release, you can just add a line of code like this:

    add_filter('wds_process_canonical', '__return_false');

    to your functions.php file, and Infinite SEO won't be adding any canonicals to your head. Since that's a full blown filter hook you can, or course, add a more elaborate processing and have the canonicals show up on some of your pages and not on others.

    For reference, the latest release comes with several other similar filters. Here's a list of them, perhaps it can help further with your customization efforts:

    add_filter('wds_process_rel_links', '__return_false'); // Removes rel=prev/next links
    add_filter('wds_process_robots', '__return_false'); // Removes robots meta
    add_filter('wds_process_keywords', '__return_false'); // Removes keywords meta

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.