Meta Tag Titles and Descriptions for Your WordPress site.

There are many good plugins out there the help you easily add meta tags to your site. All-in-one-SEO is probably the most popular of all the options. But there several reason why you may want to manually add this code to your template.

For one, you may be a template designer and want your templates to come pre-installed with this SEO friend feature.

Second, you may be having issues with Facebook link sharing not working. WordPress plugins use the wp_head() hook to access your template. But you have no control over the order. If you are using more than a dozen plugins your meta tags can get buried under tons of other code. This can prevent some bots from finding them. Indeed on several of my site Facebook’s bot was not finding them.

Third, it is just always good to do things without plugins if possible. Call it Occum’s Razor of web site building, the less code you use, the better.

Luck for us, it is extremely simple to add code for meta tags and descriptions without knowing much about wordpress or PHP.

Open the header.php file in your theme and paste in the following code:

<?php if(is_singular()) { ?>
global $post;
<?php $recent = new WP_query('p='.$post->ID);
while($recent->have_posts()) : $recent->the_post(); ?>
<meta name="title" content="<?php the_title(); ?>">
<meta name="description" content="<?php the_content_rss('', TRUE, '', 50); ?>">
<?php endwhile; ?>
<?php } else { ?>
<meta name="title" content="<?php bloginfo('title'); ?>">
<meta name="description" content="<?php bloginfo('description'); ?>">
<?php } ?>

So what’s going on here? First, we’re checking to see if the post is a single post using the WordPress Conditional tag <?php if(is_singular()); ?> because we’ll to pull the title and the description of the individual post for our meta tags. But to do this, we need to get some information about the post, which is why we use the call global $post. This will give us information about the current post. Particularly it allows us access to $post->ID to query information about the post using WP_query.

The query we us looks like this:

$recent = new WP_query('p='.$post->ID); 

Once we have the query we put it into the standard wordpress loop:

while($recent->have_posts()) : $recent->the_post();

Then we use the standard WordPress tag <?php the_title(); ?> to pull in the META TITLE and <? the_content_rss() ?> to get the description. Notice, we are not using <?php the_excerpt(); ?>. This is because this WordPress tag prints the excerpt with a “read more” link in it. This will seriously screw up your theme. Using <?php the_content_rss(); ?> allows us to specify how many words of the content to pull in. But the second parameter has to be set to TRUE to avoid pulling in a “read more” link.

SEO Basics

Good Content

In many ways, the technical aspects of SEO are becoming automated. If you use an open-source content management system, or a custom system built within the last two years, chances are you are already well optimize … at least technically.

The real competitive advantage lies in developing good content that people want to read, that has “viral” potential, and yet still advances your overall mission.

Clean URLS

In general the url of your page should reinforce the keywords you are trying to target. The link to this post is “”. Notice the term “SEO Basics” is included and that my url reflects a ration (human centered) organization.  An example of a bad or “dirty” url would be ““. If your links aren’t clean, talk to your website provider. It should be relatively easy for them to give you the necessary capabilities.

Title Tags

Title tags tell google what to put in the browser window title when the page is open. For instance, the title of this page is “SEO Basics | Mike Van Winkle”. That title is controlled by the following tags, which you can view in the source code.

<title>SEO Basics | Mike Van Winkle</title>

Note that the keywords are first in the title, the name of the site is second.

Meta Tags

The most important meta tags are the “Keyword” and “Description” tags. Here are the tags for this page.

<meta name=”description” content=”This post reviews some of the basics of SEO for small organizations and non-profits. I review meta tags, title tags, and no follow links.” />

<meta name=”keywords” content=”meta tags,search engine optimization,search engines,seo,seo basics,title tags,web marketing” />

How do you change the meta tags for your page? Unfortunately this is something that must be provided by your Content Management System. Many open-source systems like WordPress and Drupal have capabilities for this built in. Custom content management systems, which I strongly discourage, often require custom programming to enable this capability.

Heading Tags

Heading Tags set of headings and subheadings in your content. In general you should try to use these tags to reinforce your keywords, but without annoying the heck out of your readers.

<h1>SEO Basics</h1>

<h2>SEO Basics</h2>

<h3>SEO Basics</h3>

Keep in mind that your heading tags will also change the formatting.

Anchor Text/Link Attributes

We also discussed anchor text and link attributes, like titles and nofollows.

<a href=”” title=”LINK TITLE” rel=”nofollow”>ANCHOR TEXT</a>

The link title is a great opportunity to reinforce your keywords. The title for this link might be “More SEO Basics” or something similar. The same goes for the Anchor Text. Most content management systems have this capability built in. You can tell whether a link is title by simply putting your mouse over the link. Titled links will show the title in a hover box. Mouseover this link to see what I mean: SEO Basics.

You want to pay attention to the anchor text you are using to link to other pages within your site, as well as the anchor text other sites are using to link to you.

Image Alt Attribute

Similar to link titling, the Image “alt” attribute gives you an opportunity to reinforce a specific keyword or set of keywords. For instance, if you put your mouse over the image below you’ll see that a hoverbox with the terms “Seo Basics” pops up. This is because I have set the alt attribute in the image code. I can also set the image title to reflect the same keywords. Again, most content management systems these days give you the option to set these attributes as part of the normal course of posting an image. If yours doesn’t, call your provider and demand that it does.

seo basics

<img title=”seo basics” src=”×281.jpg” alt=”seo basics” width=”300″ height=”281″ />

SEO Basics Resources

Google Trends: (hot keywords) (overall SEO resource)

Yahoo Site Explorer: (Who’s linking to your site)

SpyFu: (research your competition)