SEO problems – not correct title and missing canonical link

Why is Yoast SEO outputting incorrect data?

This happened on a client project. The Yoast SEO settings looked correct, but the front end told a different story: the wrong title was rendering and the canonical link was nowhere to be found. The root cause turned out to be in the theme code and the site settings, not in the plugin.

Problem: A website had a few SEO issues: the title tag in the page source differed from what was configured in the Yoast SEO settings for that page, and the canonical link was missing.

Solution: I started by checking all the Yoast SEO settings, which looked correct. I didn’t expect the issue to be in the code itself.

Step 1. Remove hardcoded meta tags from header.php

Let’s look at the head section in the theme code:

<head>
...
<title><?php bloginfo( 'name' ); ?></title>
<meta name="description" content="<?php bloginfo( 'description' ); ?>">
<meta name="keywords" content="lorem, ipsum">
<meta name="robots" content="noindex,nofollow">
...
</head>

There are quite a few problems here. The hardcoded <title>, <meta description> and <meta keywords> tags all need to go, because Yoast manages them automatically. The keywords tag content was particularly “creative”. Make sure wp_head() is called inside <head>, and that the theme declares title support in functions.php:

add_action( 'after_setup_theme', 'helloadmin_title_support' );
function helloadmin_title_support() {
    add_theme_support( 'title-tag' );
}

Step 2. Find out why the canonical link is missing

Yoast does not output a canonical link on pages that have a noindex directive in the meta robots tag. That was exactly the case here. But even after removing the hardcoded robots tag, the canonical link still didn’t show up. The culprit was Settings → Reading → Discourage search engines from indexing this site: that option was enabled, so WordPress added its own noindex. Turning it off resolved the issue.

What to check first

Yoast SEO manages the <title>, meta description, canonical and robots tags automatically, but only if add_theme_support( 'title-tag' ) is declared and no other plugin or theme code outputs conflicting tags. If you see duplicate or incorrect tags:

  • look for hardcoded meta output in the theme’s header.php;
  • check that “Discourage search engines” is off on the live site (it is often left on after moving a site from staging);
  • check the page’s own Advanced settings in the Yoast meta box.