Missing meta description tag – Yoast SEO plugin

//Missing meta description tag – Yoast SEO plugin

Missing meta description tag – Yoast SEO plugin

Problem: missing meta description tag in <head>

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:

Solution: adding the missing wp_head() hook to the header.php file

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() to header.php

Adding the 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 </head> tag.

Description:
Fire the ‘wp_head’ action. Put this template tag immediately before </head> tag in a theme template (ex. header.php, index.php).

Usage:

Example:
file path: wp-content/themes/theme/header.php

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.
The 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.

By | 2018-06-05T14:15:51+00:00 April 5th, 2018|Tips|0 Comments