SpeeJax Header
SpeeJax logo SpeeJax

How to Add a Canonical Tag in WordPress (Step-by-Step Guide)

Adding a canonical tag in WordPress helps search engines identify the preferred URL when the same or substantially similar content is accessible through multiple URLs. You can manage canonical URLs using an SEO plugin such as Rank Math, Yoast SEO, or All in One SEO (AIOSEO), or customize them through PHP code.

However, you might not need to add a canonical tag manually. WordPress already generates canonical tags for individual posts, pages, and other singular content types through its built-in functionality. Before making changes, check whether your website already has a canonical tag and whether it points to the correct URL.

This guide explains how to add, customize, and verify canonical tags in WordPress, including situations where you need custom code.

What Is a Canonical Tag in WordPress?

A canonical tag is an HTML link element that tells search engines which URL represents the preferred version of a webpage when multiple URLs contain identical or substantially similar content.

It is commonly called a canonical tag, although technically it is a <link> element rather than a traditional meta tag.

A canonical element looks like this:

<link rel=”canonical” href=”https://www.example.com/wordpress-seo-guide/” />

The rel=”canonical” attribute identifies the link as a canonical reference, while the href attribute contains the preferred URL.

For example, suppose the same WordPress article is accessible through these URLs:

  • https://www.example.com/wordpress-seo-guide/
  • https://www.example.com/wordpress-seo-guide/?utm_source=newsletter
  • https://www.example.com/wordpress-seo-guide/?ref=email

You can identify the clean URL as the preferred version by specifying:

<link rel=”canonical” href=”https://www.example.com/wordpress-seo-guide/” />

This helps search engines understand which URL you want treated as the primary version.

Google considers canonical annotations a strong signal when selecting a canonical URL, but it can still choose a different URL based on other signals and its assessment of the available pages.

Does WordPress Automatically Add Canonical Tags?

Yes. WordPress core automatically generates canonical tags for individual content pages, including posts and pages, through its rel_canonical() function.

This functionality has been part of WordPress since version 2.9.0.

The function uses wp_get_canonical_url() to retrieve the canonical URL and outputs the corresponding HTML element in the document head.

For example, a WordPress post with this permalink:

https://www.example.com/technical-seo

can automatically receive:

<link rel=”canonical” href=”https://www.example.com/technical-seo/” />

This means you generally do not need to create a canonical tag manually for every blog post or page.

However, there is an important distinction.

WordPress core’s rel_canonical() function handles singular queries. It does not independently generate canonical tags for every possible page type, such as all category archives, tag archives, or the main posts index.

SEO plugins can provide additional canonical URL functionality across these page types.

Therefore, check your existing canonical implementation before adding another one.

How to Check Whether Your WordPress Website Already Has a Canonical Tag

Before changing any SEO settings, inspect the HTML source code of the page.

Follow these steps:

  1. Open the WordPress webpage you want to inspect.
  2. Right-click anywhere on the page.
  3. Select View Page Source.
  4. Press Ctrl + F on Windows or Command + F on Mac.
  5. Search for rel=”canonical”.
  6. Examine the URL inside the href attribute.

You should find something similar to:

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

Check whether the canonical URL matches the preferred version of the page.

You should also check whether the page contains multiple canonical elements. Normally, there should be one clear canonical URL in the HTML head.

If the existing canonical points to the correct URL, there is no reason to add another one.

If it is missing or incorrect, you can change it using an appropriate method below.

How to Add a Canonical Tag Using Rank Math

Rank Math provides a dedicated field for specifying a custom canonical URL for individual WordPress posts and pages.

You can use this feature when duplicate or substantially similar content should reference another preferred URL.

Step 1: Open the WordPress Post or Page

Log in to your WordPress dashboard.

Navigate to:

Posts → All Posts

Alternatively, select Pages → All Pages if you want to modify a webpage.

Find the content for which you want to change the canonical URL and click Edit.

Step 2: Open the Rank Math Advanced Settings

Open the Rank Math SEO panel inside the WordPress editor.

Select the Advanced tab.

If you cannot find the Advanced tab, you may need to enable Advanced Mode.

To do this, navigate to:

Rank Math SEO → Dashboard → Advanced Mode

The available interface may vary slightly depending on your WordPress editor and Rank Math version.

Step 3: Enter the Canonical URL

Locate the Canonical URL field.

Enter the complete preferred URL.

For example:

https://www.example.com/wordpress-seo-guide

Make sure you enter the destination URL you actually want search engines to recognize as the preferred version.

Step 4: Update the Post

Click Update or Publish to save your changes.

Rank Math will use the custom canonical URL when generating the canonical element for that content.

You can verify the result by opening the published webpage and inspecting its HTML source code.

How to Add a Canonical Tag Using Yoast SEO

Yoast SEO also provides a built-in option for changing canonical URLs without modifying WordPress theme files.

Follow these steps:

Step 1: Open the Content Editor

Log in to your WordPress dashboard.

Go to Posts or Pages and open the content you want to edit.

Step 2: Open Yoast SEO Settings

Find the Yoast SEO sidebar in the WordPress editor.

Navigate to the Advanced section.

Step 3: Find the Canonical URL Field

Locate the field labeled Canonical URL.

Enter your preferred URL, including the complete protocol and domain.

For example:

https://www.example.com/preferred-article

Do not enter only the page slug or a relative URL.

Step 4: Save Your Changes

Click Update or Publish.

Yoast SEO will use the specified URL when generating the canonical element.

If you leave the custom canonical field empty, the plugin uses its default canonical-generation logic.

One important consideration is that Yoast SEO does not output its canonical tag for content marked as noindex. If an expected canonical is missing, check the page’s search visibility settings before investigating other causes.

How to Add a Canonical Tag Using All in One SEO (AIOSEO)

All in One SEO provides another way to customize canonical URLs directly within the WordPress content editor.

Step 1: Edit the WordPress Page

Open your WordPress dashboard and navigate to the relevant post or page.

Click Edit to access the content settings.

Step 2: Locate AIOSEO Settings

Scroll down to the AIOSEO Settings section.

Open the Advanced tab.

Step 3: Enter Your Preferred Canonical URL

Find the Canonical URL field.

Enter the complete URL that should be treated as the preferred version.

For example:

https://www.example.com/main-service-page

Check the domain, HTTPS protocol, and URL path before saving.

Step 4: Update the Page

Click Update to save the changes.

AIOSEO will generate the canonical link element in the page’s HTML head.

You can inspect the published page source to confirm that the expected URL appears.

How to Add a Canonical Tag in WordPress Without an SEO Plugin

You can customize canonical URLs without relying on Rank Math, Yoast SEO, or AIOSEO.

However, understand how WordPress handles canonical tags before implementing custom code.

For individual posts and pages, WordPress already generates canonical elements. Simply adding another canonical-generating function can result in duplicate tags.

For a specific post or page, you can modify the canonical URL generated by WordPress using its get_canonical_url filter.

Use PHP to Change the Default Canonical URL

Open your child theme’s functions.php file or use a suitable code-snippet management method.

Add the following example:

add_filter(

    ‘get_canonical_url’,

    function ( $canonical_url, $post ) {

        if (

            $post instanceof WP_Post &&

            123 === (int) $post->ID

        ) {

            return ‘https://www.example.com/preferred-page/’;

        }

        return $canonical_url;

    },

    10,

    2

);

Replace 123 with the ID of the WordPress post or page you want to modify.

Also replace the example URL with your actual preferred canonical destination.

This code changes the canonical URL returned by WordPress core for that specific content item.

It does not automatically override a canonical element generated independently by an SEO plugin. When an SEO plugin manages your canonical URLs, use its custom field or documented developer filter instead.

Add a Canonical Element Directly to HTML

For a custom HTML page or template that does not already generate a canonical URL, you can place the following element inside its <head> section:

<head>

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

</head>

This method is appropriate when you have direct control over the HTML output.

Do not paste a fixed canonical URL into your WordPress theme’s global header.php file. That could make every page point to the same destination.

For ordinary WordPress posts and pages, using the existing core functionality or an SEO plugin is generally a better approach than inserting another HTML element manually.

How to Verify Whether Your Canonical Tag Is Working

Adding a canonical URL in WordPress is only part of the implementation. You should also confirm that the published webpage outputs the correct value.

Check the HTML Source Code

Open the published page and select View Page Source.

Search for:

rel=”canonical”

Confirm the following:

  • The canonical element exists in the HTML head.
  • There is only one canonical element.
  • The href contains the intended URL.
  • The URL uses the correct HTTPS protocol and preferred domain.
  • The canonical destination is accessible.

Check the Canonical URL in Google Search Console

Google Search Console provides additional information about Google’s canonical selection.

Open Search Console and use the URL Inspection tool.

Enter the URL you want to examine.

Review the indexing information, particularly:

User-declared canonical: The canonical URL specified by your website.

Google-selected canonical: The URL Google has selected as the representative version of the content.

Ideally, these values should match when your preferred canonical is appropriate and consistent with Google’s other signals.

If Google selects a different canonical URL, investigate the underlying reasons. Check for differences in content, internal links, redirects, sitemap entries, and other URL signals.

You can request indexing after making a correction, but Google controls when it recrawls the page and which canonical it ultimately selects.

Common Canonical Tag Problems in WordPress

Even when canonical tags are configured through a plugin, incorrect implementation can create indexing problems.

Multiple Canonical Tags on the Same Page

One common issue occurs when multiple systems generate canonical elements simultaneously.

For example, WordPress core might generate a canonical element while an additional theme function or custom code snippet outputs another one.

Multiple SEO plugins can also create overlapping metadata.

To resolve this issue, identify which component generates each element. Keep one consistent canonical implementation and remove unnecessary duplicate output.

Incorrect Canonical URL

Sometimes a page points to an outdated URL, a different domain, or an unintended destination.

Check the Canonical URL field inside your SEO plugin.

Also verify the preferred protocol, hostname, URL path, and trailing-slash convention.

The destination should be the actual preferred version of the content.

Canonical Tag Missing From the Page

If you cannot find a canonical element in the page source, investigate the following:

  • Whether WordPress is generating a canonical for that type of page.
  • Whether your SEO plugin is active.
  • Whether the page has a noindex directive.
  • Whether your theme correctly executes WordPress’s wp_head() function.
  • Whether custom code or plugin settings suppress the canonical output.
  • Whether a caching layer is serving an older version of the page.

Clear relevant website, server, and CDN caches after changing SEO settings.

Google Selects a Different Canonical URL

Adding a canonical tag does not force Google to select that URL.

If Google’s selected canonical differs from your declared canonical, review the website’s other signals.

For example, your canonical element might point to one URL while your XML sitemap and internal links consistently reference another.

Make these signals consistent wherever applicable.

Canonical Tags Used Instead of 301 Redirects

A canonical tag and a redirect serve different purposes.

If you permanently remove a webpage and want visitors to reach a replacement, use a permanent 301 redirect rather than leaving the old page accessible solely to provide a canonical signal.

Canonical Tag vs. 301 Redirect vs. Noindex

These three methods are often confused, but they solve different problems.

MethodMain purposeWhen to use it
Canonical tagIdentifies the preferred URL among duplicate or similar pagesWhen both URLs need to remain accessible
301 redirectPermanently sends visitors and crawlers to another URLWhen a page has moved or been permanently replaced
NoindexRequests that a page not appear in search resultsWhen a page should remain accessible but should not be indexed

Google considers permanent redirects a strong canonicalization signal and rel=”canonical” a strong signal as well.

A noindex directive is not a substitute for canonicalization. Google does not recommend using noindex to select a preferred URL among duplicate pages on the same website.

Choose the method that matches the actual purpose of the URL change.

Best Practices for Canonical Tags in WordPress

A correct canonical implementation requires consistency between the preferred URL and other website signals.

Keep these considerations in mind:

Use absolute URLs. Include the complete protocol and domain, such as https://www.example.com/article/, rather than relying on a relative path.

Use self-referencing canonicals where appropriate. An original, indexable page can reference its own URL as its canonical. This reinforces your preferred URL structure.

Point duplicates to relevant primary content. Do not canonicalize unrelated pages to your homepage simply because you do not want them indexed.

Keep your XML sitemap consistent. Include preferred canonical URLs rather than alternate duplicate versions.

Use consistent internal links. Link to the preferred version of a page instead of repeatedly linking to parameterized or alternate URLs.

Avoid conflicting signals. Do not declare one URL in the canonical element and another in the sitemap or through redirects.

Keep the destination accessible. The preferred canonical should be a suitable, crawlable URL that returns a successful response and is not unintentionally marked noindex.

Do not use robots.txt for canonicalization. Blocking a duplicate URL in robots.txt does not tell Google which alternative URL should be canonical.

Frequently Asked Questions

Does WordPress automatically add canonical tags?

Yes. WordPress core generates canonical tags for singular content, including individual posts and pages. SEO plugins can extend canonical management to other page types and allow users to customize individual URLs.

Do I need to add a canonical tag to every WordPress post?

No. WordPress already generates canonical URLs for individual published posts and pages through its built-in functionality. SEO plugins also provide automatic canonical generation. Manual configuration is generally necessary only when you need to override the default URL or manage a specific duplication issue.

Can I set a canonical URL to another website?

Yes. A canonical URL can point to a different domain when substantially identical content exists on multiple websites and another URL is the preferred original version.

This can be useful for legitimate content syndication. However, make sure the destination genuinely represents the same or substantially similar content.

Does a canonical tag guarantee that Google will index the preferred URL?

No. A canonical tag is a signal rather than a binding directive. Google considers the canonical annotation alongside other signals, such as redirects, internal links, sitemap information, and content similarity.

Should I use a canonical tag or a noindex tag?

Use a canonical tag when multiple similar URLs exist and you want search engines to recognize one preferred version. Use noindex when you want a page excluded from search results.

They have different purposes and should not be treated as interchangeable.

What happens if a page has two canonical tags?

Multiple canonical elements can send conflicting signals to search engines. Google may ignore conflicting annotations or choose a different canonical URL. Investigate your SEO plugins, theme, and custom code to identify and remove unnecessary duplicate elements.

Conclusion

Adding a canonical tag in WordPress is relatively straightforward when you understand how your website currently generates canonical URLs.

For most websites, WordPress core and an SEO plugin already handle the default canonical implementation. Rank Math, Yoast SEO, and AIOSEO provide dedicated settings for changing the preferred URL of individual posts and pages.

Before adding custom code, inspect the existing HTML source to avoid creating duplicate canonical elements. After making changes, verify the published URL and compare your declared canonical with Google’s selected canonical in Search Console.

The most important consideration is not simply adding a canonical tag, but ensuring that the preferred URL accurately represents the content and remains consistent with your website’s overall URL structure.

Most Useful WP Answers

How To Migrate Sitecore To WordPress

How To Sell On WordPress Without Woocommerce

Why Use WordPress Crm

Where To Buy WordPress Performance Audits

Why I Use WordPress To Design Client Websites

What Good Size Product Images WordPress

Is WordPress Good For Small Business

Can Replit Build A WordPress Plugins

How To Create A Website Like Airbnb With WordPress

How To Add Canonical Tag In WordPress

Can I Migrate From WordPress To Booking Software

How To Create A Resource Library In WordPress

Is Duda Better Than WordPress

How To Plan A Successful WordPress Website Redesign