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:
- Install and activate Yoast SEO.
- Edit any post or page.
- In the Yoast SEO meta box, click the "Advanced" tab.
- 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.