Fix Guide

How to Add a Canonical Tag in WordPress

February 8, 2026

Canonical tags are a critical part of technical SEO that many WordPress site owners overlook. A canonical tag is a small piece of HTML in the <head> section of your page that tells search engines which URL is the "official" version of that content. Without canonical tags, search engines might index multiple URLs that all show the same content, splitting your ranking power across those duplicates.

When and Why You Need Canonical Tags

You might think your site does not have duplicate content, but WordPress generates more duplicate URLs than most people realize. Here are the most common scenarios where canonical tags become essential:

  • URL parameters: Tracking parameters like ?utm_source=newsletter or ?ref=twitter create additional URLs that display the same page content. Without a canonical tag, search engines might index these parameter URLs separately.
  • www vs. non-www: If both https://example.com/page and https://www.example.com/page resolve to the same content, that counts as duplicate content.
  • HTTP vs. HTTPS: During or after an HTTPS migration, both protocol versions of your URLs might be accessible.
  • Pagination: Archive pages like /blog/page/2/ and /blog/page/3/ need canonical tags pointing to themselves (not to page 1), so search engines understand they are distinct pages.
  • Trailing slash variations: /about and /about/ are technically different URLs that can both serve the same content.
  • Similar or syndicated content: If you publish similar product descriptions across category pages, or if your content is republished on other sites, canonicals help establish the original source.

How WordPress Handles Canonical Tags by Default

Since WordPress 2.9, the platform generates a basic canonical tag automatically through the wp_head() action. As long as your theme includes <?php wp_head(); ?> in the <head> section (and virtually all themes do), WordPress will output a <link rel="canonical"> tag on singular posts and pages.

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

Setting Up Canonical Tags with Yoast SEO

Yoast SEO provides the most comprehensive canonical tag management for WordPress. Once installed, it automatically generates correct canonical URLs for every page on your site, including posts, pages, archives, categories, and taxonomies.

To set a custom canonical URL for a specific post or page:

  1. Install and activate Yoast SEO from the WordPress plugin directory.
  2. Edit the post or page where you want to set a custom canonical.
  3. Scroll down to the Yoast SEO meta box below the content editor.
  4. Click on the "Advanced" tab (the gear icon).
  5. Find the "Canonical URL" field and enter the URL you want search engines to treat as the original.
  6. Update or publish the post.

For site-wide canonical settings, Yoast handles everything automatically. It strips URL parameters, enforces your preferred URL format (www or non-www), and generates proper canonicals for paginated archives. You generally do not need to configure anything beyond installing the plugin.

Setting Up Canonical Tags with Rank Math

Rank Math is another popular SEO plugin that handles canonical tags well. The process is similar to Yoast:

  1. Install and activate Rank Math.
  2. Edit any post or page.
  3. Click the Rank Math icon in the top-right corner of the editor, or scroll to the Rank Math meta box.
  4. Go to the "Advanced" tab.
  5. Enter your custom canonical URL in the "Canonical URL" field.

Rank Math also supports auto-canonical for archives and taxonomies out of the box. In its general settings, you can configure how canonical URLs are generated across different content types.

Adding Canonical Tags Manually via functions.php

If you prefer not to use an SEO plugin, or if you need canonical tags on a custom theme with specific requirements, you can add them manually through your theme's functions.php file:

function custom_canonical_tag() {
    // Remove WordPress default canonical to avoid duplicates
    remove_action('wp_head', 'rel_canonical');

    if (is_singular()) {
        $canonical = get_permalink();
        echo '<link rel="canonical" href="' . esc_url($canonical) . '" />' . "\n";
    } elseif (is_category() || is_tag() || is_tax()) {
        $canonical = get_term_link(get_queried_object());
        if (!is_wp_error($canonical)) {
            echo '<link rel="canonical" href="' . esc_url($canonical) . '" />' . "\n";
        }
    } elseif (is_home() || is_front_page()) {
        echo '<link rel="canonical" href="' . esc_url(home_url('/')) . '" />' . "\n";
    }
}
add_action('wp_head', 'custom_canonical_tag');

This approach gives you full control, but you are responsible for handling every content type and edge case yourself. For most sites, an SEO plugin is the simpler and safer choice.

Canonical Tags on Paginated Archive Pages

One common mistake is pointing canonical tags on paginated pages back to page 1. If you have a blog archive that spans multiple pages, each page should canonical to itself. Page 2 should canonical to page 2, page 3 to page 3, and so on. These are distinct pages with different content, not duplicates.

Both Yoast SEO and Rank Math handle this correctly by default. If you are implementing canonicals manually, make sure to account for pagination:

if (is_paged()) {
    global $wp;
    $canonical = home_url($wp->request) . '/';
    echo '<link rel="canonical" href="' . esc_url($canonical) . '" />' . "\n";
}

Cross-Domain Canonicals

If the same content exists on multiple domains (for example, if your article is republished on a partner site), you can use cross-domain canonical tags to tell search engines which domain holds the original version. The partner site would include a canonical tag pointing back to your original URL.

Keep in mind that cross-domain canonicals are treated as a hint, not a directive. Google will usually respect them, but it is not guaranteed. For content syndication, cross-domain canonicals are the best practice, but you should also consider adding a "Originally published on" link as an additional signal.

Canonical Tag vs. 301 Redirect: Which to Use

Both canonical tags and 301 redirects signal to search engines that one URL is preferred over another, but they serve different purposes:

  • Use a 301 redirect: When you want to permanently move from one URL to another and users should never see the old URL. For example, after changing a page's slug or merging two pages into one.
  • Use a canonical tag: When both URLs need to remain accessible to users, but search engines should only index one version. For example, a product available at both /shoes/red-sneakers and /sale/red-sneakers.

A simple rule of thumb: 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.

How to Check Your Canonical Tags

To verify that your canonical tags are working correctly:

  • InspectWP scan: Run a scan and check the SEO section. InspectWP reports whether a canonical tag is present and shows the URL it points to.
  • View page source: Right-click on your page, select "View Page Source," and search for rel="canonical". You should find exactly one canonical tag in the <head> section.
  • Google Search Console: The URL Inspection tool shows which canonical URL Google has selected for any given page. If Google's chosen canonical differs from yours, there may be conflicting signals.

Debugging Common Canonical Problems

If your canonical tags are not working as expected, check for these common issues:

  • Multiple canonical tags: If you have an SEO plugin and your theme also outputs a canonical tag, you will end up with two competing canonicals. Search engines may ignore both. Remove the duplicate by disabling the theme's canonical output.
  • Canonical pointing to a 404: If the canonical URL returns a 404 error, search engines will ignore it. Always verify that the canonical URL is a live, accessible page.
  • Canonical pointing to a redirected URL: If your canonical points to a URL that 301-redirects elsewhere, search engines may get confused. The canonical should always point to the final destination URL.
  • Self-referencing canonicals missing: Every page should have a self-referencing canonical tag (pointing to its own URL), even if there are no known duplicates. This protects against URL parameter variations you might not be aware of.

Check your WordPress site now

InspectWP analyzes your WordPress site for security issues, SEO problems, GDPR compliance, and performance — for free.

Analyze your site free