Plugins Plugin hub Backup SEO Caching Security Forms WooCommerce Images Best backup plugins
Hosting Hosting directory Shared Managed Cloud India
Themes & builders Compare Rank Math vs Yoast
Tools All tools Hosting finder Plugin stack builder Cost calculator Salt generator Theme detector Who is hosting this? Speed test Headline analyzer robots.txt generator Redirect generator Uptime calculator Blog name generator
Best lists Best backup plugins Deals
Guides All guides Speed up WordPress Choose hosting Back up WordPress
How we test

SEO & AI search · Guide

How to Set Canonical URLs in WordPress

Short answer

To set a canonical URL in WordPress, you usually do nothing: WordPress core and your SEO plugin already add a self-referencing canonical to each page. When another address should be the main version, override it in Yoast SEO or Rank Math under the Advanced tab, using the full absolute URL. Then check the result in Search Console, where the Google-selected canonical should match the one you declared.

Key takeaways

  • A canonical URL is the one address you want search engines to treat as the main version of a page.
  • WordPress core adds a canonical link to single posts and pages, and Yoast and Rank Math add self-referencing canonicals everywhere else.
  • Redirects and rel=canonical tags are strong signals to Google, while a sitemap listing is only a weak signal.
  • In Yoast and Rank Math, override the canonical in the Advanced tab using the full absolute URL.
  • Google treats a canonical preference as a hint, not a rule, and may pick another version when signals disagree.
  • Check the Google-selected canonical in the URL Inspection tool to confirm your preference took effect.

What is a canonical URL?

A canonical URL is the one address you want search engines to treat as the main version of a page.

When several URLs show the same or very similar content, Google groups them and picks one as the canonical. That page is the one shown in search results and the one Google uses to judge content and quality.

You state your preference with a small link element in the head of the page. It looks like this: a link tag with rel=canonical and an href pointing at the preferred address.

Google calls a canonical preference a hint, not a rule. It can still pick a different version when your signals disagree, as stated in Google's canonicalization guide.

When do you need to set a canonical URL?

Set one when the same content is reachable at more than one address and you care which one Google shows.

Common cases include a product page with tracking tags on the link, a post reached through both http and https, a www and a non-www version, and a page with sorting or filter options that change the URL.

Google's own example is a product page you want people to reach at its clean address rather than through a tracked link with a code added, such as a question mark parameter at the end of the URL.

You do not need to set a canonical for every page. WordPress and your SEO plugin already add one to each page by default, and Google's guide notes your site will likely do just fine without a stated preference.

How does WordPress set canonical URLs by itself?

WordPress core adds a canonical link to single posts, pages and other singular content automatically.

The rel_canonical function outputs the link for singular queries, using wp_get_canonical_url to pick the address. It has done this since WordPress 2.9, and it was adjusted to use wp_get_canonical_url in version 4.6, as shown in the WordPress developer reference.

Your SEO plugin covers the rest. Rank Math adds canonical URLs to most pages automatically, including product pages, categories, tags and attributes, and uses the current page URL as the canonical by default, per Rank Math's canonical guide.

Yoast SEO renders the correct canonical URL for almost any page type by default, including posts, pages, categories and tags, as stated in Yoast's canonical help.

That default is called a self-referencing canonical, because the page points to itself. It is good practice, and Google recommends including one on the canonical page itself.

How do you set a canonical URL in Yoast SEO?

Open the post, page, category or tag, then set the canonical in the Advanced section of the Yoast SEO sidebar.

The steps, from Yoast's canonical help: log in to your WordPress dashboard, open the post, page, category or tag, go to Advanced in the Yoast SEO sidebar, enter the full canonical URL in the Canonical URL field, and publish or save.

Enter the full address, including https and www or non-www, exactly as it should appear. A relative path is not enough here.

You only need to change the canonical when you want a different URL to be the main version. For a normal post, leave the field blank and Yoast uses the page's own address.

If no canonical tag appears on a page, check whether the page is marked noindex. Yoast does not output a canonical tag on noindex pages, so mark the page as index to restore it.

Developers can change the output with the wpseo_canonical filter, and returning false from that filter outputs no canonical at all. Our Yoast setup guide shows where the plugin's main settings live.

How do you set a canonical URL in Rank Math?

Open the post or page, click the Rank Math SEO icon, then the Advanced tab, and enter the canonical URL.

Rank Math uses the current post or page URL as the canonical by default, so you only change it when another URL should be the main one. This default is also known as a self-referencing canonical, per Rank Math's canonical guide.

If you cannot see the Advanced tab, switch Rank Math to Advanced Mode first. Go to WordPress Dashboard, then Rank Math SEO, then Dashboard, and change the mode there.

The same Advanced tab works for posts, pages, products, categories and tags, as long as the SEO controls for that type are switched on in Rank Math SEO, then Titles and Meta.

Developers can change the output with the rank_math/frontend/canonical filter, which can also suppress the tag by returning an empty string. Our Rank Math setup guide walks through the plugin's screens.

How do you set a canonical URL without a plugin?

Add the link element to the head of your theme, or filter the value WordPress outputs.

The simplest code approach is to add a link tag in the head section of the page, pointing at the preferred address. It must sit inside the head, since Google only accepts a canonical link there.

For files that are not HTML, such as a PDF, use an HTTP header instead. Google supports a Link header with a rel=canonical target for non-HTML documents, as described in Google's canonicalization guide.

A code approach needs care: two canonical tags on one page, or a canonical that points at a 404, will confuse Google. For most sites, the plugin setting is safer than hand-written code.

How do you check your canonical URL is working?

View the page source in your browser and search for rel=canonical, then confirm it in Search Console.

The page should have exactly one canonical link in its head, pointing at the full absolute URL you expect. If you see two, or one pointing at the wrong address, your theme and your plugin may both be adding one.

Then open Google Search Console and paste the URL into the URL Inspection tool. It shows both the user-declared canonical and the Google-selected canonical, so you can see whether Google agreed with you.

When the two match, the canonical is working. When they differ, your signals disagree somewhere, and Google picked the version it judged best.

What do you do when Google picks a different canonical?

Make every signal on the page agree with the URL you want, then wait for Google to recrawl.

Google's guide lists the signals it weighs: redirects are a strong signal, a rel=canonical tag is a strong signal, and a sitemap listing is a weak one. The methods can stack, so using two or more together raises the chance your preference wins, per Google's canonicalization guide.

SignalStrengthWhat to check
301 redirectStrongOld URL redirects to the preferred URL
rel=canonical tagStrongOne tag, in the head, absolute URL
SitemapWeakOnly the preferred URL is listed
Internal linksSupportingAll links point to the preferred URL
HTTPSPreferredNo invalid certificate, no redirect to HTTP

Check the target page itself. It must return a 200 status, must not be blocked by robots.txt, and must not be marked noindex. A canonical pointing at a page Google cannot use will be ignored.

Google prefers HTTPS pages over equivalent HTTP pages as canonical, unless the HTTPS page has an invalid certificate, insecure dependencies, or a redirect back to HTTP. Fix those first if Google keeps picking the HTTP version.

If the page is a copy that should not exist at all, use a 301 redirect instead of a canonical tag. Our Yoast redirects guide shows how to set one up.

What mistakes should you avoid?

The biggest mistake is setting different canonicals for the same page in different places.

  • Do not list one URL in the sitemap and a different one in the canonical tag.
  • Do not chain canonicals, where page A points to B and B points to C.
  • Do not point a canonical at a URL that returns a 404 or redirects somewhere else.
  • Do not use a URL fragment as a canonical, since Google generally does not support fragments.
  • Do not use robots.txt to pick a canonical, because Google may still index a blocked URL without its content.
  • Do not use the URL removal tool for canonicalization, since it hides all versions of a URL from search.
  • Do not use noindex to pick a canonical inside your own site, since it blocks the page from search entirely.

Check your work after each change with the URL Inspection tool, and confirm the Google-selected canonical matches the one you declared. If a page is gone rather than duplicated, our post 404 fix guide covers the right status code to return.

Frequently asked questions

Should every page on my site have a canonical URL?

Yes, on every page, including the canonical page itself. Google recommends a self-referencing canonical, which means the page points to itself. WordPress core and both Yoast and Rank Math add one automatically, so you only need to act when you want a different URL to be the main version.

Can a canonical URL point to another website?

Yes, a canonical can point to a different domain. This is common when content is republished with permission, such as a syndicated article that should credit the original. The canonical tag tells Google which copy is the main one. The target must be a real, indexable page, or Google will ignore the tag.

What is the difference between a canonical tag and a 301 redirect?

A canonical tag is a hint that tells Google which version to show, while both pages stay live. A 301 redirect removes the duplicate and sends visitors to the new address. Use a canonical when both addresses must stay reachable, and a redirect when the duplicate should not exist at all. A redirect is also the stronger signal of the two.

Why is Google ignoring my canonical tag?

Google may ignore your canonical when the signals disagree: the target returns an error, is blocked by robots.txt, is marked noindex, or your internal links and sitemap point elsewhere. Make the redirect, the canonical tag, the sitemap and the internal links all agree on one URL, and check that the target returns a 200 status. Then wait for Google to recrawl.

How long does it take Google to respect a new canonical URL?

It can take days to weeks, because Google rechecks pages on its own schedule. Google says most sites should expect three days or more before a changed page is checked and indexed again. You can ask for a faster check with the URL Inspection tool, but the full update still depends on the crawl schedule.

Sources

  1. How to Specify a Canonical with rel="canonical" and Other Methods Google Search Central
  2. rel_canonical() WordPress Developer Resources
  3. How to change the canonical URL in Yoast SEO for WordPress Yoast
  4. Setting Canonical URLs in Rank Math Rank Math
  5. Canonical URLs: What They Are & How to Use Them for SEO Rank Math
  6. Troubleshoot Google Search Crawling Errors Google Search Central

Is your product missing, or something out of date?

Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.

About the editors

WPLegible editors

Researched from the primary sources listed above and checked against our editorial rules. About the site · How we test