How to Add a Canonical Tag in WordPress

How to Add a Canonical Tag in WordPress

Search engines like Google need clear signals to understand which page is the “main” version when multiple URLs show the same or very similar content. That’s where canonical tags come in. A canonical tag tells search engines, “This is the preferred version of this page.” If you run a WordPress site, knowing how to add canonical tags can help protect your rankings, avoid duplicate content issues, and strengthen your SEO.


Understanding Canonical Tags

A canonical tag is a small snippet of HTML placed inside the <head> section of a page. It looks like this:

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

In simple terms, it’s like pointing search engines toward the page you want to rank. For example, if both example.com/page and example.com/page?ref=twitter exist, a canonical tag tells Google which one is the master copy.

Without canonical tags, search engines may split ranking power between different versions of the same page. That can hurt your visibility. By adding them, you keep all the authority in one place.


Ways to Add Canonical Tags in WordPress

The good news is, WordPress makes it easy. Depending on how you manage your site, you can add canonical tags with plugins or by editing your theme.

1. Use an SEO Plugin (Recommended)
The simplest method is to install a trusted SEO plugin. Popular options like Yoast SEO, All in One SEO (AIOSEO), and Rank Math automatically add canonical tags to your pages and posts.

  • After installing the plugin, check the settings for “Canonical URL.”
  • Most of the time, the plugin sets the canonical tag to the page’s own URL.
  • If you want to customize it—for example, to point to another page—you can edit it directly in the page or post settings.

2. Add Canonical Tags Manually
If you prefer full control, you can add canonical tags manually by editing your theme’s header file.

  • Go to your WordPress dashboard.
  • Navigate to Appearance > Theme File Editor.
  • Open the header.php file.
  • Before the closing </head> tag, add this line:
<link rel="canonical" href="<?php echo get_permalink(); ?>" />

This ensures each page displays its own URL as the canonical link.

If you want to point to a different canonical URL, replace <?php echo get_permalink(); ?> with the specific link.

3. Add Canonical Tags with Functions.php
Another method is to use your theme’s functions.php file. This approach lets you automate canonical tags without editing the header directly.

Example code:

function add_canonical_tag() {
    if (is_singular()) {
        echo '<link rel="canonical" href="' . get_permalink() . '" />' . "\n";
    }
}
add_action('wp_head', 'add_canonical_tag');

This snippet will output a canonical tag for each post or page.


Closing Signals of Clarity

Adding a canonical tag in WordPress is one of the simplest yet most powerful steps you can take for SEO. Whether you use a plugin or add the code yourself, you’re sending a clear signal to search engines about which version of your content matters most.

The beauty of WordPress is that it gives us options. You can keep things simple with an SEO plugin, or you can roll up your sleeves and add the code by hand. Either way, the result is the same: cleaner search results, stronger rankings, and peace of mind knowing your content is protected.

When you guide search engines with clarity, they reward you with better visibility. And that’s the true value of a well-placed canonical tag.