Fix Guide

How to Add a Canonical Tag in WordPress

February 8, 2026

Canonical tags tell search engines which URL version of a page should be indexed. Here's how to properly implement them in WordPress.



Method 1: WordPress Default (Built-in)


Since WordPress 2.9, a canonical tag is automatically added via wp_head(). Make sure your theme includes <?php wp_head(); ?> in the <head> section — most themes do.



Method 2: Yoast SEO (Recommended)


Yoast SEO provides full control over canonical URLs:



  1. Install and activate Yoast SEO.

  2. Edit any post or page.

  3. In the Yoast SEO meta box, click the "Advanced" tab.

  4. Enter a custom canonical URL if needed.


Yoast automatically generates the correct canonical for each page and handles pagination, categories, and archives.



Method 3: Manual via functions.php


If you don't use an SEO plugin, you can add canonical tags programmatically:


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


Important Considerations



  • The canonical URL should always be the absolute URL (including https://)

  • Paginated pages should canonical to themselves (page 2 canonicals to page 2)

  • Don't canonical non-duplicate pages to each other — only use it for truly duplicate content



Verify with InspectWP


Run an InspectWP scan to check if your canonical tag is present and points to the correct URL.

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