Skip to content

How to Add Canonical Tag in WordPress

This guide teaches you how to add canonical tag in WordPress using popular SEO plugins or manual code insertion. You’ll learn why canonical tags matter for SEO and how to verify they’re working correctly.

Key Takeaways

  • Canonical tags prevent duplicate content: They tell search engines which version of a page is the original, improving your SEO rankings.
  • Most SEO plugins auto-generate canonical tags: Tools like Yoast SEO and Rank Math handle this automatically—no coding needed.
  • Manual insertion is possible via functions.php: Advanced users can add canonical tags using a simple PHP snippet in their theme.
  • Always test your canonical tags: Use Google Search Console or browser inspection tools to confirm they’re implemented correctly.
  • Avoid conflicting canonical URLs: Ensure only one canonical tag exists per page to prevent SEO confusion.
  • Use child themes for safety: If editing theme files, always use a child theme to preserve changes during updates—learn more about what is a child theme in WordPress.
  • Canonical tags work with pagination and archives: Properly configured, they help manage SEO for category pages and blog listings.

What Is a Canonical Tag and Why Does It Matter?

If you’ve ever published the same content on multiple pages—or if your site has URLs that look almost identical—you might be hurting your SEO without realizing it. That’s where the canonical tag comes in. This small piece of HTML tells search engines which version of a page is the “master” or preferred one.

For example, if your blog post appears at both yoursite.com/blog/post and yoursite.com/blog/post?utm_source=newsletter, search engines might see these as duplicate content. A canonical tag points both URLs to the clean version, consolidating ranking signals and avoiding penalties.

In short: adding canonical tags in WordPress helps you control how search engines index your content, leading to better visibility and fewer indexing errors.

How to Add Canonical Tag in WordPress (3 Easy Methods)

There are three main ways to add canonical tags in WordPress: using SEO plugins, manually editing theme files, or using a custom code snippet. We’ll walk you through each method step by step.

How to Add Canonical Tag in WordPress

Visual guide about How to Add Canonical Tag in WordPress

Image source: magecomp.com

Method 1: Use an SEO Plugin (Recommended for Most Users)

The easiest and safest way to add canonical tags is by using a trusted SEO plugin. Two of the most popular options—Yoast SEO and Rank Math—handle canonical URLs automatically.

Step 1: Install and Activate Yoast SEO

  • Go to Plugins > Add New in your WordPress dashboard.
  • Search for “Yoast SEO” and click Install Now, then Activate.

Step 2: Configure Canonical Settings

  • Navigate to SEO > Search Appearance.
  • Click the Content Types tab.
  • Under “Posts” or “Pages,” make sure “Show canonical URL” is enabled.
  • Yoast will now automatically add a self-referencing canonical tag to every post and page.

Step 3: Set Custom Canonical URLs (Optional)

  • Edit any post or page.
  • Scroll down to the Yoast SEO meta box.
  • Click “Advanced” and enter a custom canonical URL if needed (e.g., if content is syndicated).

Tip: Rank Math works similarly—just go to Rank Math > Titles & Meta and enable canonical tags under the appropriate content type.

Method 2: Add Canonical Tag Manually via functions.php

If you prefer not to use a plugin or need more control, you can add canonical tags manually by editing your theme’s functions.php file. Important: Always use a child theme to avoid losing changes when updating your theme. If you’re unsure how to set one up, check out our guide on what is a child theme in WordPress.

Step 1: Access Your Theme Files

  • Go to Appearance > Theme File Editor.
  • From the right sidebar, select functions.php under your active child theme.

Step 2: Add the Canonical Tag Code

Paste the following PHP snippet at the end of the file:


function add_canonical_tag() {
    if ( is_singular() ) {
        global $wp;
        $current_url = home_url( add_query_arg( array(), $wp->request ) );
        echo '' . "\n";
    }
}
add_action( 'wp_head', 'add_canonical_tag' );

This code automatically generates a self-referencing canonical tag for all single posts, pages, and custom post types.

Step 3: Save and Test

  • Click Update File.
  • Visit any post or page on your site.
  • Right-click and select “View Page Source.”
  • Search for rel="canonical"—you should see your tag in the <head> section.

Method 3: Use a Custom Plugin (For Developers)

If you manage multiple sites or want a reusable solution, consider creating a tiny custom plugin. This keeps your canonical logic separate from your theme.

Step 1: Create a New Plugin File

  • Go to wp-content/plugins/ via FTP or your hosting file manager.
  • Create a new folder called custom-canonical-tags.
  • Inside it, create a file named custom-canonical-tags.php.

Step 2: Add Plugin Header and Code

Paste this code into the file:


request ) );
        echo '' . "\n";
    }
}
add_action( 'wp_head', 'custom_add_canonical_tag' );

Step 3: Activate the Plugin

  • Go to Plugins > Installed Plugins.
  • Find “Custom Canonical Tags” and click Activate.

Now your site will output canonical tags without touching theme files.

Troubleshooting Common Canonical Tag Issues

Even with the best setup, things can go wrong. Here’s how to fix the most common problems:

Multiple Canonical Tags on One Page

If you see more than one rel="canonical" tag, it’s usually because both your theme and an SEO plugin are adding them. To fix:

  • Disable canonical output in your theme (if it has that option).
  • Or switch to a plugin-only method and remove manual code.

Canonical Tag Points to Wrong URL

This often happens with HTTP/HTTPS or www/non-www mismatches. Ensure your WordPress Address (URL) and Site Address (URL) in Settings > General match your preferred domain format (e.g., always use https://www.yoursite.com).

Canonical Tag Missing on Certain Pages

If some pages lack canonical tags, check if they’re excluded by your plugin settings or conditional logic. For example, archive pages or search results may not need them—but if they do, adjust your code or plugin rules accordingly.

How to Verify Your Canonical Tags Are Working

  • Use Google Search Console: Go to URL Inspection and check the “Coverage” report for canonical issues.
  • Browser inspection: Right-click > “View Page Source” and search for canonical.
  • Online tools: Try free checkers like Sitechecker.pro or Screaming Frog (in list mode).

Best Practices for Using Canonical Tags in WordPress

Adding canonical tags is just the first step. Follow these best practices to get the most SEO benefit:

  • Always use absolute URLs: Include the full https://yoursite.com/page—not relative paths.
  • Self-reference by default: Unless you’re syndicating content, point the canonical tag to the current page’s URL.
  • Update canonicals after URL changes: If you change a permalink, ensure the canonical tag reflects the new URL.
  • Don’t use noindex and canonical together: If a page is set to noindex, a canonical tag is usually unnecessary.
  • Test after major updates: After updating themes or plugins, double-check that canonical tags still appear correctly.

Conclusion

Adding canonical tags in WordPress doesn’t have to be complicated. Whether you use a plugin like Yoast SEO, edit your theme files carefully, or build a custom solution, the key is consistency and accuracy. By implementing canonical tags correctly, you’ll help search engines understand your content structure, avoid duplicate content penalties, and improve your site’s overall SEO performance.

Remember: always test your implementation and keep your site’s URL structure clean. And if you ever need to modify your theme—whether to add canonical tags or adjust styling—consider learning the best way to add CSS in WordPress website to keep your customizations safe and organized.