Canonical tags on a WordPress site are supposed to tell search engines “this URL is the authoritative version of this content.” When they’re wrong — pointing at the staging domain, the home page, an unpaginated version, or a URL with tracking parameters stripped incorrectly — search engines deindex the wrong version and rank the wrong one. The bugs are subtle. The diagnostic is mechanical.
What’s happening
WordPress core, the active theme, and any SEO plugin (Yoast, Rank Math, AIOSEO, SEOPress) each can emit a <link rel="canonical"> tag. WordPress core emits a basic one based on get_permalink(). The SEO plugin usually emits its own, intended to override core’s. If both fire, you get duplicate canonical tags — Google picks one, but it’s not deterministic which. On paginated archives (/category/news/page/3/), the canonical should point at that specific page, not the unpaginated root. After a migration, the canonical can hard-code the old domain via cached values or hardcoded home_url() overrides.
How to verify
From any host with curl:
curl -s https://example.com/some-post/ | grep -i 'rel="canonical"'
curl -s https://example.com/category/news/page/3/ | grep -i 'rel="canonical"'
curl -s "https://example.com/?utm_source=newsletter" | grep -i 'rel="canonical"'
curl -s https://example.com/page/2/ | grep -i 'rel="canonical"'
You want exactly one canonical tag per URL. The canonical on /some-post/ should be https://example.com/some-post/. The canonical on /category/news/page/3/ should be the paginated URL itself. The canonical on the URL with ?utm_source= should drop the parameter and point at the clean URL. From WP-CLI:
wp eval 'var_dump(wp_get_canonical_url(123));'
wp option get home
wp option get siteurl
wp search-replace 'oldstaging.com' 'example.com' --dry-run
The fix
-
Duplicate canonical tags. If
curlshows tworel="canonical"lines, both core and the SEO plugin are firing. Disable core’s: in a must-use plugin,remove_action('wp_head', 'rel_canonical'). Yoast and Rank Math do this automatically but theme code occasionally re-adds it. Stack Harbor’s enterprise WordPress baseline keeps canonical handling in exactly one source. -
Cross-domain after migration. If the canonical points at the old domain (
canonical href="https://oldsite.com/post/"instead ofhttps://example.com/post/), checkwp option get homeandwp option get siteurl. Then runwp search-replace 'https://oldsite.com' 'https://example.com'across the database — but use--all-tables-with-prefixto catch SEO plugin tables. -
Paginated archives. WordPress core’s canonical on a paginated archive should be the paginated URL (
/category/news/page/3/), not the root (/category/news/). On WordPress 5.5+, this is correct by default. If the SEO plugin overrides incorrectly, check the plugin’s pagination settings. Yoast: SEO > Search Appearance > Archives > pagination handling. -
Query parameter pollution. Tracking parameters (
?utm_source=,?fbclid=,?gclid=) should be stripped from the canonical. WordPress core does this. If your URLs render with parameters in the canonical, a theme function is overriding — greptheme/:grep -rn "canonical" wp-content/themes/<active>/. -
WooCommerce product variations. Product variations and
?orderby=parameters on shop archives should not have unique canonicals. WooCommerce sets the canonical to the parent product page; verify this is intact after WooCommerce updates. -
Self-referential canonicals on duplicate content. When
https://example.com/about/andhttps://example.com/about(with trailing slash difference) both return 200 with self-referential canonicals, you’ve created two indexable URLs for the same content. Pick one as canonical via the SEO plugin’s redirect feature, 301 the other. -
CDN/cache layer. Some CDN setups strip the canonical header during transformation. Compare
curlagainst origin vs CDN:curl --resolve example.com:443:<origin-ip> -s https://example.com/ | grep canonicalvs the public URL. If they differ, the CDN is the problem. -
HTTPS migration leftover. After an HTTP-to-HTTPS migration, the canonical should be HTTPS. WP-CLI:
wp option get homeshould start withhttps://. If it doesn’t, the WordPress URL settings never updated. Stack Harbor’s enterprise WordPress migration scripts validate this as a smoke test.
Stack Harbor handles canonical configuration as part of enterprise WordPress operations. Start the conversation when Search Console reports duplicate content with conflicting canonicals.