Yoast SEO Plugin – Theme fix

Yoast SEO Plugin   Theme fixThe title tag is an important SEO page element. The title tag:

  • defines a title in the browser toolbar
  • provides a title for the page when it is added to favorites
  • displays a title for the page in search-engine results

If you’re using the WordPress SEO by Yoast Plugin you’ll probably need to manually edit your theme’s header file to correctly display title tags. It’s easy to do.

So that this plugin can change your page titles, the title section of your header.php file should look like this:

<title><?php wp_title(''); ?></title>

Many themes, including the Twenty-Ten and Twenty-Eleven themes that come with WordPress, add extra code that you’ll need to remove in order for this plugin to work properly.

  1. Open your header.php file (Appearance -> Editor -> navigate on right side to header.php)
  2. Locate the opening <title> tag near the top of the file
  3. Highlight all code from this opening tag to the closing </title> tag and replace it with <?php wp_title(”); ?> keeping the opening and closing title tags in place.
  4. Click update file

For the Twenty-ten theme you are replacing these lines of code

<title><?php
	/*
	 * Print the <title> tag based on what is being viewed.
	 */
	global $page, $paged;

	wp_title( '|', true, 'right' );

	// Add the blog name.
	bloginfo( 'name' );

	// Add the blog description for the home/front page.
	$site_description = get_bloginfo( 'description', 'display' );
	if ( $site_description && ( is_home() || is_front_page() ) )
		echo " | $site_description";

	// Add a page number if necessary:
	if ( $paged >= 2 || $page >= 2 )
		echo ' | ' . sprintf( __( 'Page %s', 'twentyten' ),
                  max( $paged, $page ) );

	?></title>

with this line

<title><?php wp_title(''); ?></title>

and for the Twenty-Eleven theme you are replacing these lines of code

<title><?php
	/*
	 * Print the <title> tag based on what is being viewed.
	 */
	global $page, $paged;

	wp_title( '|', true, 'right' );

	// Add the blog name.
	bloginfo( 'name' );

	// Add the blog description for the home/front page.
	$site_description = get_bloginfo( 'description', 'display' );
	if ( $site_description && ( is_home() || is_front_page() ) )
		echo " | $site_description";

	// Add a page number if necessary:
	if ( $paged >= 2 || $page >= 2 )
		echo ' | ' . sprintf( __( 'Page %s', 'twentyeleven' ), max( $paged, $page ) );

	?></title>

with this line

<title><?php wp_title(''); ?></title>

Once you’ve made this change, the WordPress SEO by Yoast Plugin will be able to fully customize the page title tags of your WordPress website.

If the idea of editing your header file is too much for you, the WordPress SEO plugin does have a little tick box that you can use. SEO -> Titles -> Force rewrite titles. Be aware that changing your template will be faster.

I hope that I’ve explained this simply enough so that you are able to do this yourself. If you need any help or have anything else to say about this post please add a comment below.

3 comments on “Yoast SEO Plugin – Theme fix
  1. Dawn Comber says:

    You’ve laid your instructions out so well that those of us with less technical knowledge can actually implement the change. Thanks!

  2. CentOS 6 says:

    Wouldn’t it be better to move it into a function using a child theme ?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>