Canonical tags tell search engines which version of a URL should be indexed when the same content is available at multiple URLs. WordPress adds canonical tags automatically to standard pages and posts, so you do not need a separate plugin for them.
This works well for standard content, but paginated and archive pages require extra configuration. SEO plugins such as Yoast SEO, Rank Math, and SEOPress can add the required canonical tags automatically, usually without any additional setup.
If you want to keep your site lightweight and avoid installing another plugin, you can add a custom canonical tag function instead.
Without canonical tags, search engines may see different URL variants as separate pages. This can divide ranking signals and cause the wrong URL to appear in search results.
Key Takeaways
- By default, WordPress adds canonical meta tags for single posts and pages, but not for archive pages like categories, tags, custom taxonomies, and authors.
- SEO plugins can add these canonical tags automatically. If you prefer not to use extra tools, you can add them with custom PHP code instead.
- Make sure you have only one canonical tag per page, and set its canonical URL directly to the preferred page rather than to a URL that redirects.
What Is a Canonical Tag?
To decide which version of a URL should be listed in search results, Google considers multiple signals, including redirects, meta tags, and sitemaps URLs.
When a page is reachable at multiple URLs, the canonical tag points to the one you want indexed. The tag sits in the
<head>
section and is invisible to visitors. View the page source and you will find it as a single line:
<link rel="canonical" href="https://example.com/preferred-page/" />
Why Are Canonical Tags Important?
Search engines use the canonical tag to identify the preferred URL when the same content is available through multiple URL variants. Without it, crawlers may choose a different URL, which can cause the wrong URL variant to appear in search results.
Multiple URLs can also split ranking signals between them instead of consolidating those signals for the preferred URL. This can weaken the page's authority and reduce its SEO value.
It can also waste crawl budget, especially on large websites with many pages, and delay the discovery and indexing of new or updated high-priority content.
Canonical Tag vs Canonical Redirect: What's the Difference?
Both canonical tags and canonical redirects help prevent duplicate content issues, and you can use them together.
A canonical tag tells search engines which URL you prefer, while other URL variants can still be accessible. A canonical redirect enforces the preferred URL and redirects requests from other variants to that URL.
| Feature | Canonical Tag | Canonical Redirect |
|---|---|---|
| Purpose | Tells search engines which URL version should be treated as the preferred one. | Redirects visitors and crawlers to the preferred URL. |
| Implementation | An HTML
<link rel="canonical">
element added to the page
<head>
. | A server-side HTTP redirect, usually a 301 or 302 redirect. |
| User Experience | Visitors remain on the original URL they requested. | Visitors are automatically sent to the canonical URL. |
| Search Engine Signal | Recommendation that search engines may ignore. | Strong signal that consolidates URL variants into a single address. |
| Duplicate Content Control | Helps search engines understand which URL variant should be indexed. | Prevents access to alternative URL versions by redirecting them. |
| Link Equity Consolidation | Usually consolidates ranking signals, depending on search engine interpretation. | Passes ranking signals directly to the destination URL. |
| Crawl Budget Impact | Alternative URLs may still be crawled by search engines. | Prevents crawling of duplicate URL variations. |
| Best Use Case | When duplicate or similar pages need to remain available to users. | When old or alternative URLs should no longer be accessible. |
| SEO Reliability | Moderate. It is treated as a hint by search engines. | High. It is treated as a stronger directive. |
How WordPress Handles Canonical URLs by Default
WordPress adds a canonical meta tag to the HTML output of standard single posts and pages without requiring a plugin. The built-in functionality does not cover archive requests, so category, tag, custom taxonomy, and author archive pages have no canonical tag by default.
WordPress core has received several proposals to address this limitation. One of the earliest dates back to 2011, when Nathan Rice proposed adding archive pages support to the relevant function. The proposal was discussed but never implemented, and the related Trac ticket remains open.
For now, you need a dedicated SEO plugin or a custom PHP snippet if you want to add canonical tags to archive pages.
How to Add Canonical Tag in the Header of WordPress?
Method 1: Use WordPress’s Built-In Canonical Tags
You may not need a plugin or custom snippet to generate canonical tags. If your website only contains standard posts and pages and does not use categories, tags, custom taxonomies, or archive pages, WordPress likely already generates the canonical tags you need.
WordPress 2.9, released in December 2009, introduced native canonical URL support through the core rel_canonical() function. WordPress uses this function to generate a
<link rel="canonical">
tag for single posts, pages, and custom post type items.
If your theme calls
wp_head()
inside the
<head>
section, as virtually all themes do, WordPress already adds the canonical tag for you. You do not need a plugin or custom code for this.
Method 2: How to Set a Canonical Tag Without a Plugin
The snippet below replaces the built-in function and adds a canonical tag to all public WordPress post types, taxonomies, and archive pages:
- Front page
- Blog index page
- Single posts, pages, and custom post types
- Paginated content
- Category and taxonomy archives
- Author archives
- Date-based archives (year/month/day)
This gives you full control over the canonical URL logic, so you can adjust it to match your set-up. The code has been tested with the most common WordPress setups, but it may not be compatible with every plugin or configuration you have installed.
If you prefer, you can add the code with a plugin such as Code Snippets or paste it directly to the functions.php file of your child theme.
<?php
/**
* Remove the built-in canonical tag to make sure that is not duplicated
* with the new custom code
*/
remove_action( 'wp_head', 'rel_canonical' );
/**
* Adds a canonical <link> tag to the <head> for various types of pages.
*
* Supports single posts/pages, taxonomies, custom post type archives,
* author archives, date archives, and paginated archives.
*
* @return void
*/
function add_canonical_link() {
	$canonical_url = '';
	// A. Canonical URL for the front page.
	if ( is_front_page() ) {
		$canonical_url = home_url( '/' );
	} // B. Canonical URL for the blog posts page.
	elseif ( is_home() ) {
		$page_id = get_option( 'page_for_posts' );
		$canonical_url = $page_id ? get_permalink( $page_id ) : get_home_url();
	} // C. Canonical URL for single posts/pages/CPT items
	else if ( is_singular() ) {
		$canonical_url = wp_get_canonical_url();
	} // D. Canonical URL for archive pages
	elseif ( is_category() || is_tax() || is_post_type_archive() || is_author() || is_date() ) {
		$canonical_url = get_archive_link( get_queried_object() );
	}
	if ( ! empty( $canonical_url ) ) {
		echo '<link rel="canonical" href="' . esc_url( $canonical_url ) . '" />' . PHP_EOL;
	}
}
add_action( 'wp_head', 'add_canonical_link' );
Most ready-made snippets you find online for adding a canonical tag without a plugin rely on
get_permalink()
alone to get the canonical URL. That works for single posts and pages, but it does not cover author archives, other archive pages, or paginated URLs.
To add a canonical tag to these pages without using a plugin, your code needs an additional part that retrieves the correct canonical permalink, because
get_permalink()
alone cannot handle these URLs.
/**
* Returns the archive link for a taxonomy term or post type archive,
* including pagination when applicable.
*
* @param object $archive The queried object.
*
* @return string
*/
function get_archive_link( $archive ) {
	$link = '';
	if ( is_category() || is_tax() ) {
		$link = get_term_link( $archive );
	} elseif ( is_post_type_archive() ) {
		$link = get_post_type_archive_link( $archive->name );
	} elseif ( is_author() ) {
		$link = get_author_posts_url( $archive->ID );
	} elseif ( is_date() ) {
		$link = get_date_archive_link();
	}
	if ( empty( $link ) ) {
		return '';
	}
	$paged = max( 1, get_query_var( 'paged' ) );
	if ( $paged > 1 ) {
		$link = get_pagenum_link( $paged );
	}
	return $link;
}
/**
* Returns the canonical URL for a date archive (year, month, or day).
*
* @return string Canonical URL for the date archive.
*/
function get_date_archive_link() {
	$year = absint( get_query_var( 'year' ) );
	$month = absint( get_query_var( 'monthnum' ) );
	$day = absint( get_query_var( 'day' ) );
	if ( $year && $month && $day ) {
		return get_day_link( $year, $month, $day );
	}
	if ( $year && $month ) {
		return get_month_link( $year, $month );
	}
	if ( $year ) {
		return get_year_link( $year );
	}
	return '';
}
Method 3: Using an SEO Plugin (Yoast / Rank Math / SEOPress)
Most SEO plugins handle canonical tags for you automatically, so you do not need to add any extra PHP code. If you already have an SEO plugin installed, this is often the easiest option, particularly if you are not comfortable working with PHP or editing theme files.
This functionality is available in Yoast SEO, Rank Math, SEOPress and other similar plugins.
The trade-off is having another plugin to manage. There is also a risk that your theme or another plugin may generate their own meta tags, which can cause duplicate canonical tags.
Common Mistakes When Adding Canonical Tags in WordPress
Duplicate Canonical Tags
WordPress does not need a custom function for every page. Its built-in
rel_canonical()
function generates a canonical URL for singular content items, including posts, pages, and custom post types.
This means that adding another
wp_head
callback without first removing or overwriting the built-in function can result in two canonical tags on the same page.
For example:
<link rel="canonical" href="https://example.com/example-page/" />
<link rel="canonical" href="https://example.com/example-page/" />
Even when both URLs are identical, there is no reason to output the same canonical twice.
If you only need standard self-referencing canonicals for posts, pages, and custom post types, WordPress's built-in implementation may already be sufficient.
Missing Canonical Tags on Archive Pages
WordPress’s built-in
rel_canonical()
function handles canonical tags for individual posts, pages, and custom post type items, but not for archive pages. Category, tag, custom taxonomy, author, and date archives therefore have no canonical tag by default.
Without an SEO plugin or custom code to add these missing tags, pagination, filtering, and sorting can create multiple URLs that display the same or very similar content. A canonical tag tells search engines which URL should be treated as the preferred version.
Pointing Canonical Tags to Redirected URLs
A canonical URL should resolve directly to the preferred page and return a 200 (OK) status without a redirect. If the canonical URL redirects with a 301 to another URL, you are sending search engines mixed signals.
The canonical tag identifies one URL as the preferred version, while the redirect tells crawlers to use a different URL. Crawlers will usually follow the redirect and treat the final destination as canonical, but it is better to avoid this conflicting setup.

Leave a Reply