Abstract website paths converging on one preferred page

How to Add a Canonical Tag in WordPress: Safe Methods and Checks

A canonical tag tells search engines which URL should represent similar or duplicate WordPress pages. Learn safe ways to add one, when not to use it, and how to verify the result.

To add a canonical tag in WordPress, you need to identify the preferred URL, add one accurate rel="canonical" element to the page head, and verify that WordPress is not already generating a different tag. In most sites, an SEO plugin is the safest method because it handles canonical URLs dynamically as content and site settings change.

A canonical tag does not redirect visitors or delete duplicate pages. It is a signal that tells search engines which URL should be treated as the primary version when several URLs contain substantially similar content.

If your site already has conflicting or broken canonical tags, start with our guide to fixing broken canonical tags and duplicate URL issues rather than adding another tag on top of the problem.

What a canonical tag does

A canonical tag is an HTML link element placed inside the document’s <head> section. A typical self-referencing canonical 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 of the current content. Common situations include:

  • HTTP and HTTPS versions of the same page.
  • URLs with tracking parameters such as ?utm_source=newsletter.
  • Several paths that display the same product, post, or landing page.
  • Print, filter, sort, or campaign URLs that should not be treated as separate primary pages.
  • A page that is accessible with and without a trailing slash, when both versions resolve.

Canonicalization is a hint, not an absolute command. Search engines may select a different canonical if the declared URL redirects, returns an error, contains different content, or conflicts with other signals such as internal links and XML sitemaps.

Before you add a canonical tag

Do not add a canonical simply because a tool reports a missing tag. First decide whether the page should be indexed at all and whether another URL genuinely represents the same content.

Choose the correct preferred URL

The preferred URL should normally be the final, public URL that loads successfully over HTTPS. It should return a normal success response, avoid unnecessary redirects, and use the site’s established permalink format.

  1. Open the page in a private browser window.
  2. Copy the final URL after any redirect has completed.
  3. Check whether the page works with the correct domain, protocol, and trailing-slash format.
  4. Compare the page with the URL you plan to declare canonical.
  5. Use the other URL only if it is substantially equivalent and the canonical page is the version you want discovered.

Do not canonicalize unrelated pages to the homepage just because they are thin, old, or difficult to optimize. Use a redirect, a noindex directive, improved content, or removal when those options better describe the page.

Check for an existing tag first

Open the page in a browser, right-click, choose View Page Source, and search for rel="canonical". You should normally find one canonical element. Inspect its full URL, not just the beginning of the line.

If a plugin already outputs a canonical tag, edit that plugin’s canonical field instead of inserting a second tag in a theme file. The existing article on multiple canonical tags in WordPress covers the risks of duplicate declarations and how to isolate their source.

Method 1: Add a canonical with an SEO plugin

Developer inspecting a webpage head element

Most established WordPress SEO plugins provide a canonical URL field on the post, page, taxonomy, or product editing screen. The exact label and location vary by plugin version.

  1. Back up the site or confirm that your existing backup is usable.
  2. Open the post or page in WordPress.
  3. Find the plugin’s SEO panel, often below the editor or in a sidebar.
  4. Open the advanced settings, if necessary.
  5. Locate the Canonical URL or Canonical URL override field.
  6. Enter the complete preferred URL, including https://.
  7. Save or update the content.
  8. Clear the page, plugin, server, and CDN caches if cached HTML is enabled.

For a normal, original post or page, leaving the canonical field empty is often correct: the plugin will generate a self-referencing canonical automatically. Enter a custom URL only when you have a specific reason, such as a near-duplicate page whose primary version lives elsewhere.

For sitewide behavior, use the plugin’s global settings rather than adding the same hard-coded tag to every template. Review archive, author, search, attachment, and pagination settings carefully because these URL types may need different treatment.

Method 2: Add a canonical programmatically

Developers can generate canonical tags through WordPress hooks, but the code must account for page types, pagination, HTTPS, and existing SEO-plugin output. A simple hard-coded tag in header.php is usually unsafe because it can declare the same URL for every page.

For a custom implementation, use WordPress’s document-head hook and generate a properly escaped URL:

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. Do not deploy it without confirming that another component is not already printing a canonical tag. A custom theme or plugin should also define how archives, taxonomies, paginated views, and special URL parameters are handled.

Put custom functionality in a site-specific plugin or a child-theme implementation rather than editing a parent theme. Parent-theme updates can overwrite direct changes. Test the code on a staging site before applying it to production.

For hook details and WordPress development guidance, consult the official WordPress Developer Resources.

How to verify the canonical tag

Adding a tag is only half the job. Verify both the HTML delivered to visitors and the URL behavior around it.

Check the source HTML

  1. Open the public page while logged out.
  2. View the page source, not only the visual inspector.
  3. Search for rel="canonical".
  4. Confirm that exactly one canonical tag is present.
  5. Check that the URL is absolute, uses HTTPS, and matches the intended preferred page.

The source may differ from what you see in an editor because caching, server-side rendering, or a CDN can deliver older HTML. Purge relevant caches and check again if the old value remains.

Test the canonical 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. If it redirects, update the canonical to the final destination where practical.

Secure URL verification with a check mark

Test common variations such as HTTP, HTTPS, a www or non-www hostname, uppercase paths, and tracking parameters. Your site-wide redirect policy should keep alternate versions from competing with the canonical URL. If SSL changes created redirect problems, see our guide to WordPress redirect loops after SSL or Cloudflare changes.

Common canonical mistakes

Adding two canonical tags

This often happens when a developer adds a theme tag while an SEO plugin already generates one. Remove the duplicate source and retain the declaration managed by the system that understands your content types.

Using a relative URL

Prefer a complete absolute URL such as https://example.com/page/. It is clearer, easier to audit, and less vulnerable to protocol or path interpretation problems.

Pointing every page to the homepage

A homepage is not a substitute for the correct canonical of every article, service page, or product. This can prevent individual pages from being treated as the primary result for their own content.

Canonicalizing to a noindex or blocked URL

The destination should be crawlable and available. A canonical pointing to a page blocked by robots rules, marked noindex, or returning an error sends conflicting signals.

Internal links should generally use the preferred URL directly. Update menus, related-post links, XML sitemaps, and templates when alternate URLs are being generated unnecessarily.

When a canonical tag is not the right fix

  • Permanent duplicate URL: use a server redirect when visitors should always land on one URL.
  • Private or low-value content: consider access controls or a noindex directive, depending on the purpose of the page.
  • Different content: keep separate pages canonical to themselves if they serve different search intents.
  • Temporary campaign URL: retain the campaign page when it has a legitimate purpose, but make its indexing strategy deliberate.
  • Broken URL: repair the page, redirect it, or remove it; do not use a canonical to conceal an error.

If WordPress is producing unexpected tags, changing URLs, or showing canonical warnings after a migration or plugin update, a controlled site review is safer than adding more header code. WP Fix It’s WordPress Site Repair service can help investigate complex configuration conflicts.

Quick canonical checklist

  • Choose one genuine preferred URL.
  • Confirm the destination loads successfully over HTTPS.
  • Check the page source before adding anything.
  • Use one canonical-management method wherever possible.
  • Keep the canonical absolute and correctly escaped.
  • Do not point unrelated pages to the homepage.
  • Clear caches after changing the tag.
  • Verify the final HTML while logged out.
  • Align internal links and sitemaps with the preferred URL.

For broader WordPress troubleshooting references, the official WordPress Documentation provides current guidance on managing and maintaining a WordPress site.