A trick to turn off description tag output in All in One SEO

The WordPress SEO plugin "All in One SEO (AIOSEO)" allows you to bulk-specify description tags, but
If you have written description tags directly in your theme or are outputting them with another plugin,
Even if you do this...
<head>
<meta charset="utf-8">
<title>記事のタイトル</title>
<meta name="description" content="<?php the_title(); ?>についてご紹介">
(省略)
</head>
The description tag will be overwritten like this.
<head>
<meta charset="utf-8">
<meta name="description" content="○○についてご紹介">
<!-- All in One SEO 4.X -->
<title>記事のタイトル - サイトのタイトル</title>
<meta name="description" content="AIOSEOデフォルトだと記事の冒頭の文章が入る">
<!-- All in One SEO -->
(省略)
</head>
Here's a trick to turn off the output of the description tag in All in One SEO.
By the way, if you want to do the same for title tags, click here:
Conclusion
Filter hooks are used.
Paste this into functions.php.
// Turn off description
add_filter( 'aioseo_description', 'aioseo_filter_description' );
function aioseo_filter_description( $description ) {
return false;
}
Then, the description tag will not be output on all pages.
If you want to turn it off only for specific pages, such as "posts and static pages only", do this:
// Turn off description
add_filter( 'aioseo_description', 'aioseo_filter_description' );
function aioseo_filter_description( $description ) {
if ( is_single() || is_page() ) {
return false;
}
return $description;
}
If you determine the target page and return false, the tag will not be output.
The official documentation is here:
Notes
This filter hook is originally intended to rewrite the description, so what happens if you return false? This is not mentioned in the official documentation.
However, if you look at all-in-one-seo-pack/app/Common/Views/main/meta.php in the plugin folder,
<?php if ( $description ) : ?>
<meta name="description" content="<?php echo esc_attr( $description ); ?>" />
<?php endif; ?>
It is written to be output when "$description" is true, and if you return false with the filter hook, this variable becomes an empty string and thus false, so it seems unlikely to cause an error in AIOSEO version 4.1.8 in the test environment.
Therefore, it might not be used as intended, so please proceed at your own risk if you are able to maintain it.
If anything changes in future updates, please let me know in the comments.




If this was helpful, we appreciate your support!
Any support received will be used for childcare.
Or support us by buying something from the buttons below
(You don't have to buy the linked product.)
Amazon
楽天市場
Yahoo!ショッピング
PR