Problem: missing meta description tag in
Recently, we had an issue where one of our client’s sites had the meta description tag missing from the page source code.
This was the meta description set through the Yoast SEO meta box in the back-end page editor, and would output into the page source code in the following format:
<meta name="description" content="The meta description..."/>
Solution: adding the missing
wp_head() hook to the
First port of call, was to check the theme’s
header.php file for the
wp_head() hook, but none could be found.
Many plugins depend on this hook to add elements to the
<head> of pages, such as meta tags.
After inserting this hook into the file, and reloading the page, the meta description tags, with the defined values set through Yoast, were visible and present in the page source code.
Guideline: on adding
wp_head() hook into the
header.php is quite simple and straight forward, all you need to do is make sure you add it in the right place, and that is before the closing
Fire the ‘wp_head’ action. Put this template tag immediately before
</head> tag in a theme template (ex.
<?php wp_head(); ?>
/* Always have wp_head() just before the closing </head>
* tag of your theme, or you will break many plugins, which
* generally use this hook to add elements to <head> such
* as styles, scripts, and meta tags.
How does this happen?
Themes must pass the theme review process before being made available via the WordPress.org theme repository, which is the official WordPress Theme directory.
wp_head() hook is required in order to pass this process, so you can rest assured that any theme you download from the WordPress.org theme repository will contain this essential hook; any commercial theme should as well.
However, some custom bespoke themes may not, as they are usually exempt from the theme review process.