If you use Yoast (an SEO plugin) and Raft (a theme), you may notice that pages contain duplicate <title>
tags. Duplicate tags can negatively impact SEO, so it makes sense to fix the issue even though it does not visibly impact users. Unfortunately, the issue cannot be fixed by changing any settings in either Yoast or Raft. When both are used together, two <title>
tags are generated.
Root cause
You can skip this section if you are not interested in the root cause. Jump to the Workarounds section below.
By default, the Raft theme declares support for title-tag
. This signals that the theme itself will not output a <title>
tag, leaving WordPress (and plugins like Yoast SEO) responsible for generating it. This code is implemented in the Raft source code at inc/Core.php
.
Yoast SEO checks whether the active theme supports title-tag
. If it does, Yoast assumes it can safely output the <title>
tag, since the theme won’t. This logic is implemented in the plugin’s source code at src/integrations/front-end-integration.php
.
However, WordPress also generates a <title>
tag when title-tag
support is declared. As a result, both Yoast and WordPress may output their own <title>
tags, leading to duplicates in the page’s HTML.
Workarounds
Fortunately, Github user erminrajic found a workaround: disable Raft’s support for title-tag. Yoast does not write a <title>
tag if the current theme does not support title-tag
. This leaves the <title>
tag written by WordPress.
Option 1: Add a code snippet
The following snippet stops Yoast from writing a <title>
tag. It does this by removing Raft’s support for title-tag
, which must be present for Yoast to write a title. WordPress will still write a <title>
.
You will need a code snippet plugin that lets you add custom snippets of code to WordPress. This is preferrable to editing your theme, which will get overridden when you update to the next version. A few popular snippet plugins are FluentSnippets and Code Snippets.
add_action( 'after_setup_theme', function() {
remove_theme_support( 'title-tag' );
}, 20 );
Note: if you apply this snippet and do not see a change, try flushing your website cache. If you still cannot see it, try clearing your local cache. If you still cannot see it, adjust the priority of the snippet in your snippet plugin. It is possible that the snippet is not executing early enough in the page lifecycle, depending on how your snippet plugin is injecting code into the session.
Option 2: Modify Raft
Alternately, you can modify Raft with your Theme File Editor. This is not recommended because your changes will get lost when the theme is updated. However, this approach does let you work around the issue without a code plugin.
- From the side menu select Tools > Theme File Editor
- Open the file inc/Core.php.
- Scroll down and comment out the following line:
Before:
add_theme_support( 'title-tag' );
After:
// add_theme_support( 'title-tag' );
Remember, you will lose your changes if you update the theme.
Reference
- Duplicate title tag when using Yoast SEO plugin · Issue #137 · Codeinwp/raft – the GitHub issue for this bug.
- Title Tags in 4.1 – Make WordPress Core – information about the title-tag feature when it was first announced.
- add_action() – Function | Developer.WordPress.org
- add_theme_support() – Function | Developer.WordPress.org
- remove_theme_support() – Function | Developer.WordPress.org
Leave a Reply