The meta tags go in the <head>
section of each page, which in a WordPress theme is in header.php
.
header.php
file.<meta name="description" content="Description of content that contains top keyword phrases"/> <meta name="keywords" content="Key words and phrases, comma separated, not directly used in content - google ignores this tag but used in other engines as a fall back"/> <title>Open Source Online Magazine</title>
title
meta tag. In the space where you've just deleted the existing code, add the following:<title><?php wp_title('|','true','right'), ?><?php bloginfo('name'), ?></title>
<meta name="description" content="<?php bloginfo('description'), ?>" >
header.php
file and switch to your browser. Visit the page for one of your blog posts and take a look at the title displayed.We added some meta tags to our theme, specifically the title
tag and a description
meta tag. Let's check the code we used:
Our title
tag includes two elements:
wp_title('|','true','right')
:wp_title
is the WordPress template tag which displays the title of the current post or page'|'
displays a separator'true'
tells WordPress to display (or echo
, in PHP terms) the page title, rather than just fetching it for later useright
of the page titlebloginfo('name')
to display the site name—it's that handy bloginfo
tag again.Our description meta tag uses the content attribute to display the site description using bloginfo('description')
Why no meta tag for keywords?
We haven't included a meta tag for keywords as Google no longer uses keywords when generating search results. This is because keywords were so widely abused in the past that they became unreliable. If you wanted to use keywords (for example, if you're optimizing for a search engine that does still use keywords), the best approach is to use a plugin.
So let's have a look at our post, as viewed in the Safari browser:
You can see our title displayed by the browser. However, you can't see the description. To check that, let's look at the code generated for this page:
<title>Post with a shorter title but more text | Open Source Magazine</title> <meta name="description" content="Using Open Source for work and play" >
As you can see, our description is there too. Well done!