dalewatkins

« Who is lying about SEO? | Website Theme: Watercolor »

Wordpress: Use Custom Fields for Keywords and Descriptions

[Tags: , ]

There are several basic SEO “best practices” everyone should take when building a website.
Now, I’m not talking about tricks or gimmicks to try to cheat the system, I’m talking about tried and true techniques that work on every search engine.
Most of you know what they are: alt attributes for img tags, good content structure, title attributes for anchor tags, etc. The list goes on and on.
A couple of oldies but goodies that should never be omitted are meta tags for keywords and descriptions.

“Aren’t Keywords and Descriptions old news?”

Well, duh!
Keywords and descriptions have been around for a loooong time, but their purpose today is different from their purpose in the beginning of search engine rankings.
Search engines no longer rely on these meta tags to determine rankings because you SEO cheaters out there abused the system and ruined it for everyone. I’m not bitter though, honest.
Some search engines do use the description meta tag for display in search results to give the reader a better idea of what you’re up to.
So, if the meta description can be used to entice users to visit your site, then use it!

The problem

Wordpress, like other database driven sites, does not have a designated place to insert unique meta tags for each post or page.
Uh oh, not good.

The solution

Wordpress does have custom fields that can be accessed via code.
Hooray!
Declaring a custom field does not inject it directly into the code, you have to access it using php and Wordpress functions.
Let’s take a closer look….

The steps

I am not getting into specifics here about meta tags, just the nitty gritty. Meta tags are found inside the <head> tags of a website and the attributes we are interested in declaring are the name and content attributes.

  1. Find your <head> tags:
    Sign into Wordpress as an admin and navigate to the Appearance > Editor so you can edit the template files for your website. Your template may be different, but my <head> tags are located in the header.php file, so check there first.
  2. Insert the code:

    <?php
    if (is_single() | is_page(49)) {
       if ($keyword = get_post_meta($post->ID, 'meta_keywords', true)) {
          echo '<meta name="keyword" content="'.$keyword.'" />';
       }
       if ($desc = get_post_meta($post->ID, 'meta_description', true)) {
          echo '<meta name="description" content="'.$desc.'" />';
       }
    }
    ?>

    To kick this off, a couple of Wordpress functions determine if the page being loaded is a single post or if the page matches a number. The reason for checking the page number is for when you want to add custom fields to pages that are not single posts. This is most useful if there is custom css or javascript code for use only on that one page, like a javascript portfolio image browser.
    Anyways, now the script looks for custom fields (or meta data) in the post and when it finds them, it formats the data for the appropriate meta tag.
  3. Add the custom field to your posts:
    The only thing left to do is add the custom fields to your posts.
    Do this by scrolling down to the Custom Fields section and add fields with the names meta_keywords and meta_description. Include the information you want to appear in the content attribute of the field and it will now populate correctly in your <head> section.

Other modifications

This example was made to display keywords and descriptions for specific pages or posts.
In most cases, I take these two meta tags and place them outside of the if statement to include them on every page, it’s just better for SEO.
The technique in the example code above is best used to define page specific CSS and javascript for individual posts and pages that might require them. You might want to define a custom field called “custom_css” or “custom_js,” its up to you.

Other uses for custom fields

I think custom fields are great for page and post specific CSS, javascript, keywords, and descriptions.
What other ways do you use Custom Fields in Wordpress?

You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

4 Responses to “Wordpress: Use Custom Fields for Keywords and Descriptions”

  1. Really nice post, Thanks again for a nice site.

  2. Nga Amsberry on January 2nd, 2010 at 3:36 am
  3. Thanks.

  4. Dale Watkins on January 2nd, 2010 at 9:22 am
  5. well I can agree with this entry, have you ever researched about how new signature linking is? I read a paper somewhere about it being very effective for search engine optimization.

  6. Get Indexed Yahoo on January 3rd, 2010 at 9:44 pm
  7. yeah,, nice post! i can’t use AIO SEO pack on my free hosted blog. hmm manual is not always bad right? thx!

  8. fenny on January 7th, 2010 at 12:44 pm