How to Set Canonical URL in WordPress

Small business owner checking a canonical URL on a laptop, with a highlighted canonical tag in the page source on screen and a printed SEO checklist on the desk.

Direct answer

Set a canonical URL in WordPress by checking what your site already adds first: WordPress core and your SEO plugin add a self-referencing canonical to every page. Only override it when another address should be the main version, using the Canonical URL field in Yoast SEO or Rank Math, then confirm in Search Console that Google picked the same address.

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, per wplegible.com. When several URLs show the same or very similar content, Google groups them and picks one as the canonical, per wplegible.com.

You state your preference with a small link element in the head of the page, per wplegible.com. It looks like this:

<link rel="canonical" href="https://example.com/example-page/" />

This tells crawlers that the URL in the href attribute is the preferred version, per wpfixit.com, and a page should have exactly one of them, per pixellize.io.

Google calls a canonical preference a hint, not a rule, and may pick another version when signals disagree, per wplegible.com, citing Google. The default on a healthy WordPress site is a self-referencing canonical, because the page points to itself, and Google recommends including one on the canonical page itself, per wplegible.com.

Canonical, redirect or noindex: pick the right tool

A canonical is one of three tools for duplicate URLs, and each does a different job.

Method Use it when What happens to the duplicate
Canonical tag Both URLs must stay live for users Both stay live; Google shows one version
301 redirect The duplicate should not exist at all Visitors and Google move to the main URL
Noindex The page should not appear in search Page stays live but is hidden from results

A canonical keeps both pages live while Google shows one version; a 301 redirect removes the duplicate and sends visitors to the new address, per wplegible.com. The rule of thumb is simple: if users should be able to visit both URLs, use a canonical; if the old URL should no longer be visited at all, use a 301 redirect, per inspectwp.com.

When do you need to set one?

Set a canonical when the same content is reachable at more than one address and you care which one Google shows, per wplegible.com. Common cases are tracking tags on a link, http and https versions, www and non-www versions, and sorting or filter options that change the URL, per wplegible.com.

WordPress creates more duplicate addresses than most owners realise. URL parameters such as ?utm_source=newsletter create additional URLs that display the same page content, per inspectwp.com.

A canonical also covers content that lives in two places on purpose. A canonical can point to a different domain, which is common when content is republished with permission, per wplegible.com.

You do not need to set a canonical for every page. WordPress and your SEO plugin already add one to each page by default, per wplegible.com. If your site has wider duplicate problems, start with our guide on how to fix duplicate content on WordPress first.

What WordPress already does for you

WordPress core adds a canonical link to single posts, pages and other singular content automatically, per wplegible.com. The rel_canonical function outputs the link for singular queries, using wp_get_canonical_url to pick the address, per wplegible.com. It has done this since WordPress 2.9, per wplegible.com, citing the WordPress developer reference.

The built-in version is fairly limited, per inspectwp.com. It does not handle archive pages, custom post types, or edge cases particularly well, per inspectwp.com. That is why most SEO professionals recommend using a dedicated SEO plugin for proper canonical management, per inspectwp.com.

Your SEO plugin covers the rest. Rank Math adds canonical URLs to most pages automatically and uses the current page URL as the canonical by default, per wplegible.com, citing Rank Math. Yoast SEO renders the correct canonical URL for almost any page type by default, per wplegible.com, citing Yoast.

So on most WordPress sites you are not adding a canonical. You are checking and correcting the one the plugin prints.

Step 1: Check what your page already declares

Before you add anything, find out what is already there. Open the page in a browser, right-click, choose View Page Source, and search for rel=”canonical”, per wpfixit.com. You should normally find one canonical element, per wpfixit.com. Inspect its full URL, not just the beginning of the line, per wpfixit.com.

The page should have exactly one canonical link in its head, pointing at the full absolute URL you expect, per wplegible.com. If you see two, or one pointing at the wrong address, your theme and your plugin may both be adding one, per wplegible.com. If a plugin already outputs a canonical tag, edit that plugin’s canonical field instead of inserting a second tag in a theme file, per wpfixit.com.

Check the source while logged out, because caching, server-side rendering, or a CDN can deliver older HTML, per wpfixit.com.

Then test the destination. Open the canonical URL directly. It should resolve to the intended page without a redirect chain, login requirement, 404 response, or unexpected domain change, per wpfixit.com. A canonical pointing to a 404 will be ignored, and one pointing to a redirected URL confuses search engines, so it should always point to the final destination URL, per inspectwp.com.

The preferred URL should normally be the final, public URL that loads successfully over HTTPS, returns a normal success response, and uses the site’s established permalink format, per wpfixit.com. Your canonical must match your permalink form, so read our guide on how to optimise WordPress permalinks for SEO first if you have not settled that yet.

Step 2: Set a custom canonical in Yoast SEO

The steps, from Yoast’s canonical help, are: 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, per wplegible.com, citing Yoast.

Enter the full address, including https and www or non-www, exactly as it should appear: a relative path is not enough, per wplegible.com. Use an absolute URL, not a relative path, because Google accepts relative canonicals but they are easy to get wrong, per pixellize.io.

You only need to change the canonical when you want a different URL to be the main version, per wplegible.com. For a normal, original post or page, leaving the canonical field empty is often correct: the plugin will generate a self-referencing canonical automatically, per wpfixit.com. Enter a custom URL only when you have a specific reason, such as a near-duplicate page whose primary version lives elsewhere, per wpfixit.com.

Filling the canonical field when a blank self-referencing default was correct is the single most common canonical mistake in Pixellize audits, per pixellize.io. If no canonical tag appears on a page, check whether the page is marked noindex, per wplegible.com. Yoast does not output a canonical tag on noindex pages, so mark the page as index to restore it, per wplegible.com.

Step 3: Set a custom canonical in Rank Math

In Rank Math, the field sits in the same place. Open the post or page, click the Rank Math SEO icon, then the Advanced tab, and enter the canonical URL, per wplegible.com. 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, per wplegible.com.

If you cannot see the Advanced tab, switch Rank Math to Advanced Mode first, under WordPress Dashboard, then Rank Math SEO, then Dashboard, per wplegible.com.

Leave the field blank to keep the automatic self-referencing canonical, per pixellize.io.

Step 4: Set one without a plugin

If you run no SEO plugin, WordPress still prints a canonical on single posts and pages, but you have no field to override it. The code route below changes that. A simple hard-coded tag in header.php is usually unsafe because it can declare the same URL for every page, per wpfixit.com.

Add this to your site using the document-head hook, per wpfixit.com:

add_action( 'wp_head', function () {
    if ( is_singular() ) {
        $canonical = wp_get_canonical_url();
        if ( $canonical ) {
            printf(
                '<link rel="canonical" href="%s" />',
                esc_url( $canonical )
            );
        }
    }
} );

This example is intentionally limited to singular content and may overlap with an SEO plugin’s output, per wpfixit.com. Do not deploy it without confirming that another component is not already printing a canonical tag, per wpfixit.com.

Put custom functionality in a site-specific plugin or a child-theme implementation rather than editing a parent theme, per wpfixit.com. For files that are not HTML, such as a PDF, use an HTTP Link header with a rel=canonical target instead, per wplegible.com, citing Google. If a page has both a header canonical and an HTML canonical, and they disagree, you are sending Google a mixed signal, so pick one, per pixellize.io.

For most small business sites, the plugin field is the safer choice.

Step 5: Check Google agreed with you

Changing the tag is only half the job. Open Google Search Console and paste the URL into the URL Inspection tool, per wplegible.com. It shows both the user-declared canonical and the Google-selected canonical, so you can see whether Google agreed with you, per wplegible.com. When they match, the canonical is working; when they differ, your signals disagree somewhere, per wplegible.com.

Google’s guide lists the signals it weighs, and they are not equal: redirects are a strong signal, a rel=canonical tag is a strong signal, and a sitemap listing is a weak one, per wplegible.com, citing Google.

Signal Strength What to check
301 redirect Strong Old URL redirects to the preferred URL
rel=canonical tag Strong One tag, in the head, absolute URL
Sitemap Weak Only the preferred URL is listed
Internal links Supporting All links point to the preferred URL
HTTPS Preferred No invalid certificate, no redirect to HTTP

The target page itself must return a 200 status, must not be blocked by robots.txt, and must not be marked noindex, per wplegible.com. 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, so fix those first if Google keeps picking the HTTP version, per wplegible.com, citing Google.

Do not use a URL fragment as a canonical, since Google generally does not support fragments, per wplegible.com.

Make every signal agree with the URL you want, then wait for Google to recrawl, per wplegible.com. Google says most sites should expect three days or more before a changed page is checked and indexed again, per wplegible.com.

Worked example: this site’s own canonicals

This site’s own live pages show what a healthy setup looks like: every post already carries exactly one self-referencing canonical, added by Yoast SEO. Here are six, checked live on 1 Dec 2026.

Live URL on this site Canonical tag found Words in the slug Characters in the slug
/how-to-do-keyword-research-small-business-website-free/ 1, self-referencing 9 words 54 characters
/how-to-use-long-tail-keywords-for-small-business-seo/ 1, self-referencing 10 words 52 characters
/how-to-find-low-competition-keywords-for-a-small-business/ 1, self-referencing 10 words 57 characters
/how-to-check-keyword-difficulty-for-free/ 1, self-referencing 7 words 40 characters
/how-to-check-keyword-difficulty-in-bulk/ 1, self-referencing 7 words 39 characters
/how-to-export-keywords-from-google-search-console/ 1, self-referencing 8 words 49 characters

The lesson is that a working canonical setup is boring on purpose. All six slugs are 39 to 57 characters, and each page’s canonical tag points at its own full address, including https and the trailing slash. Nothing was typed into a Canonical URL field for any of them.

A real problem would look different: two canonical tags on one page, a canonical pointing at an old http address, or one pointing at a page that now redirects. Any of those is a reason to open the Advanced tab and run the URL Inspection check again.

How often should you check your canonicals?

A quarterly pass is enough for most small business sites.

  • After a publish: check the new page’s source once for its one self-referencing canonical.
  • After a migration: when you change domain, protocol, or permalink structure, check your most important pages first.
  • After a plugin change: when you switch SEO plugins or themes, check that only one source prints the tag.
  • After a Search Console warning: when a page shows “Duplicate without user-selected canonical” or “Google chose different canonical than user”, open URL Inspection and compare the two canonical lines.
  • Every quarter: re-run the view-source check on a handful of pages.

Common mistakes to avoid

Adding two canonical tags. This often happens when a developer adds a theme tag while an SEO plugin already generates one, per wpfixit.com. Remove the duplicate source, per wpfixit.com.

Using a relative URL. Prefer a complete absolute URL, with https and the full domain, over a relative path, per wpfixit.com. It is clearer, easier to audit, and less vulnerable to interpretation problems, per wpfixit.com.

Pointing every page to the homepage. A homepage is not a substitute for the correct canonical of every article, service page, or product, per wpfixit.com. Do not canonicalize unrelated pages to the homepage just because they are thin, old, or difficult to optimize, per wpfixit.com.

Canonicalizing to a noindex or blocked URL. A canonical pointing to a page blocked by robots rules, marked noindex, or returning an error sends conflicting signals, so the destination must be crawlable and available, per wpfixit.com.

Changing canonicals without updating internal links. Internal links should generally use the preferred URL directly, per wpfixit.com. Update menus, related-post links, sitemaps, and templates when alternate URLs are generated unnecessarily, per wpfixit.com.

Using a canonical instead of a redirect. A canonical tag does not redirect visitors or delete duplicate pages, per wpfixit.com. If the duplicate should not exist at all, a 301 redirect is the honest answer. It is also the wrong tool for two pages competing for one keyword: that needs the routine in our guide on how to fix keyword cannibalisation on WordPress.

Chaining canonicals. Do not chain canonicals, where page A points to B and B points to C, per wplegible.com. Every canonical should point at the final page, not at another pointer.

Frequently asked questions

What is a canonical URL in simple terms?
A canonical URL is the one address you want search engines to treat as the main version of a page, per wplegible.com. When several addresses show the same content, the tag tells Google which one to index and show.

Do I need to set a canonical URL for every page?
No. WordPress core and your SEO plugin already add a self-referencing canonical to every page by default, per wplegible.com. You only act when you want a different URL to be the main version, per wplegible.com.

How do I check my canonical URL?
Open the page, right-click, choose View Page Source, and search for rel=”canonical”, per wpfixit.com. You should find exactly one tag in the head, pointing at the full absolute URL you expect, per wplegible.com.

Can a canonical URL point to another website?
Yes. A canonical can point to a different domain, which is common when content is republished with permission, per wplegible.com. The target must be a real, indexable page, or Google will ignore the tag, per wplegible.com.

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, per wplegible.com. A 301 redirect removes the duplicate and sends visitors to the new address, per wplegible.com.

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, per wplegible.com. Make every signal agree on one URL, and check that the target returns a 200 status, per wplegible.com.

Conclusion

Setting a canonical URL in WordPress is mostly a checking job. WordPress and your SEO plugin already add a self-referencing canonical to every page, so check the source first, change the field only when another address should be the main version, and confirm in Search Console that Google picked the same one. One page, one canonical, one address.