How to change the 404 page title tag in All in One SEO

Here's how to change the title tag of 404 pages to any value in the WordPress SEO plugin All in One SEO (AIOSEO).
From what I've researched, there are articles suggesting that you just shouldn't execute wp_head() on 404 pages, but that feels a bit strange, doesn't it?
Conclusion
Add the title tag for 404 pages inside the <head> of header.php.
<?php if(is_404()): ?>
<title>404 Not Found</title>
<?php endif; ?>
(略)
<?php wp_head(); ?>
wp_head() is fine to keep as usual.
Add the following code to functions.php.
//Turn off title tag for 404 pages
add_filter( 'aioseo_disable_title_rewrites', 'aioseo_disable_term_title_rewrites' );
function aioseo_disable_term_title_rewrites( $disabled ) {
if ( is_404() ) {
return true;
}
return false;
}
This filter hook disables the title tag output only for 404 pages.
aioseo_disable_title_rewrites - AIOSEO
Click here for more details about this filter hook. (Though it's not that detailed...)
What was happening
In All in One SEO, you cannot set the title for 404 pages.
Therefore, an empty title tag is output on 404 pages.
<!-- All in One SEO 4.x.x.x - aioseo.com -->
<title></title>
(略)
So, the idea is to detect 404 pages and insert a unique title tag, but...
<?php if(is_404()): ?>
<title>404 Not Found</title>
<?php endif; ?>
(略)
<?php wp_head(); ?>
As long as wp_head() is executed, this happens, and it gets overwritten by an empty title tag.
404 page output result
<title>404 Not Found</title>
(略)
<!-- All in One SEO 4.x.x.x - aioseo.com -->
<title></title>
(略)
So, one more step.
That's why I added a filter hook to disable the title tag output only for 404 pages.
functions.php
//Turn off title tag for 404 pages
add_filter( 'aioseo_disable_title_rewrites', 'aioseo_disable_term_title_rewrites' );
function aioseo_disable_term_title_rewrites( $disabled ) {
if ( is_404() ) {
return true;
}
return false;
}




If this was helpful, we appreciate your support!
All support received will go toward my child's upbringing.
Author's Baby Registry (Amazon)
Support me on OFUSE
Or support me by buying something from the buttons below
(You don't have to buy the specific item linked.)
Support me via Amazon
Support me via Rakuten
Support me via Yahoo!Shopping
PR