SEO Tips & Tricks: They Don’t Want You to Know About

Customizing Meta Tags in Wordpress

by John H. Gohde on July 26, 2009

Or, How to Replace the All in One SEO Plugin

Implementing Search Engine Optimization (SEO) through Meta Tags in Wordpress is extremely easy to do. All it takes is inserting one big elseif PHP statement inside of your Wordpress theme. This is the safest way to approach SEO in Wordpress, since once your Theme has been customized, if your blog is up and running then your blog will always be optimized exactly the way that you would want it to be.

To understand exactly what I am doing, it would help if you knew something about Important HTML Meta Tags. In addition, this post is part of a long series of posts on Customizing Wordpress Themes. You should browse through this category of posts in sequence, starting with the first post listed for background information on how to customize Wordpress themes. The entire topic of Replacing the All in One SEO Plugin will be covered in its own series of posts.

All for One SEO in PHP

The code to be added to your theme is coded in a subset of PHP that is used by Wordpress. While I am sure that there are programmers who love coding in PHP, personally I find it to be a total mess. There are way too many variations of a PHP elseif statement floating around. Therefore, I would strongly suggest that you should stick with the style that I have chosen to use.

To be totally safe, I recommend that you should first backup your entire theme, or at least the header.php file. We will be modifying the theme template which creates the HTML header section of a webpage. This is usually contained in the Header (header.php) template. Therefore, you need to find some way to backup this particular template. I would suggest the use of a good FTP program. But, you could conceivably do this by copying and pasting it into the Windows Notepad text editor.

If this big PHP elseif statement is too intimidating for you then you should check out SEO Your Blog which offers a more simplified version which I had developed a while back.

 

Replacing the All for One SEO Plugin

The procedure is basically to select the entire following section of PHP coding with your mouse, copy it, and then paste it into near the very top of your header.php template.

 

   <?php /*   The Main Page   */ ?>
<?php if ( is_front_page() && is_paged() ) { ?>
<?php   echo ‘<meta name="robots" content="noindex, follow, noarchive, nosnippet" />’; ?>
<?php } elseif (is_front_page()) { ?>
<title><?php bloginfo(‘name’); ?></title>
<?php /*   Edit Website Description   */ ?>
<?php   echo ‘<meta name="description" content="Enter your Website Description here." />’; ?>
<?php   echo "\n"; ?>
<?php /*   Edit Website Keywords   */ ?>
<?php   echo ‘<meta name="keywords" content="List your, keywords, here" />’; ?>
<?php   echo "\n"; ?>
<?php   echo ‘<meta name="robots" content="index, follow, noodp, noydir" />’; ?>

<?php /*   A Single Post   */ ?>
<?php } elseif (is_single()) { ?>
<?php $my_title = wp_title(, FALSE); ?>
<?php $my_title = trim($my_title); ?>
<title><?php echo $my_title; ?> | <?php bloginfo(‘name’); ?></title>
<?php
global $wp_query, $post;
$seo_new=get_post_meta($post->ID, "description", true);
$seo_old=get_post_meta($post->ID, "_aioseop_description", true);
if($seo_new)
print ‘<meta name="description" content="’.$seo_new.‘" />’;
else
print ‘<meta name="description" content="’.$seo_old.‘" />’;
?>

<?php /*   A Single Page   */ ?>
<?php } elseif (is_page()) { ?>
<?php $my_title = wp_title(, FALSE); ?>
<?php $my_title = trim($my_title); ?>
<title><?php echo $my_title ?> | <?php bloginfo(‘name’); ?></title>
<?php
global $wp_query, $post;
$seo_new=get_post_meta($post->ID, "description", true);
$seo_old=get_post_meta($post->ID, "_aioseop_description", true);
if($seo_new)
print ‘<meta name="description" content="’.$seo_new.‘" />’;
else
print ‘<meta name="description" content="’.$seo_old.‘" />’;
?>

<?php /*   Tags   */ ?>
<?php } elseif (is_tag()  && is_paged() ) { ?>
<?php $my_title = single_cat_title(, FALSE); ?>
<?php $my_title = trim($my_title); ?>
<title><?php echo $my_title; ?><?php echo $random_string = chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)); ?>  | <?php bloginfo(‘name’); ?></title>
<?php } elseif (is_tag()) { ?>
<?php $my_title = single_cat_title(, FALSE); ?>
<?php $my_title = trim($my_title); ?>
<title><?php echo $my_title; ?> Tag | <?php bloginfo(‘name’); ?></title>

<?php /*   Categories   */ ?>
<?php } elseif (is_category()  && is_paged() ) { ?>
<?php $my_title = single_cat_title(, FALSE); ?>
<?php $my_title = trim($my_title); ?>
<title><?php echo $my_title; ?><?php echo $random_string = chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)); ?>  | <?php bloginfo(‘name’); ?></title>
<?php
$cat = trim(category_description());
$cat = ereg_replace(‘<p>’, , $cat);
$cat = ereg_replace(‘</p>’, , $cat);
$rand1 = chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(32);
$rand2 = chr(32) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57));
$beg = ‘<meta name="description" content="’;
$end = ‘" />’;
$full = $beg.$rand1.$cat.$rand2.$end;
?>
<?php echo $full; ?>
<?php } elseif (is_category()) { ?>
<?php $my_title = single_cat_title(, FALSE); ?>
<?php $my_title = trim($my_title); ?>
<title><?php echo $my_title; ?> | <?php bloginfo(‘name’); ?></title>
<?php
$cat = trim(category_description());
$cat = ereg_replace(‘<p>’, , $cat);
$cat = ereg_replace(‘</p>’, , $cat);
$beg = ‘<meta name="description" content="’;
$end = ‘" />’;
$full = $beg.$cat.$end;
?>
<?php echo $full; ?>

<?php /*   Archives   */ ?>
<?php } elseif (is_archive() && is_paged() ) { ?>
<title><?php wp_title(); ?>  - <?php echo $random_string = chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)); ?> | <?php bloginfo(‘name’); ?>
</title>
<?php } elseif (is_archive()) { ?>
<?php $my_title = wp_title(, FALSE); ?>
<?php $my_title = trim($my_title); ?>
<title><?php echo $my_title; ?> Archive | <?php bloginfo(‘name’); ?></title>

<?php /*   Searches   */ ?>
<?php } elseif (is_search()) { ?>
<title>Search | <?php bloginfo(‘name’); ?></title>
<?php   echo ‘<meta name="robots" content="noindex, follow, noarchive, nosnippet" />’; ?>

<?php /*   Everything else is NOT indexed   */ ?>
<?php } else { ?>
<?php   echo ‘<meta name="robots" content="noindex, follow, noarchive, nosnippet" />’; ?>

<?php } ?>
 

More precisely, this big PHP elseif statement should go directly below the code that should look something like the following.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="<?php bloginfo(’html_type’); ?>; charset=<?php bloginfo(’charset’); ?>" />
 

Editing of this code may either be done directly in the Wordpress theme editor which is located under Appearance, or in Windows Notepad text editor. I would suggest using Notepad, as the latest version of the theme editor is not all that easy to use.

This big PHP elseif statement is divided up into sections that start with a comment that looks something like the following.

<?php /*   Comment   */ ?>
 

Which is followed by a blank line. The only thing that really needs to be edited is the website description and keywords meta tags, which are located in the Main Page section on the very top of this big PHP statement.

The website description (i.e., Enter your Website Description here.) would be edited in the following section of coding.

<?php /*   Edit Website Description   */ ?>
<?php   echo ‘<meta name="description" content="Enter your Website Description here." />’; ?>
 

The website Keywords (i.e., List your, keywords, here) would be edited in the following section of coding. Separate your keywords with a comma.

<?php /*   Edit Website Keywords   */ ?>
<?php   echo ‘<meta name="keywords" content="List your, keywords, here" />’; ?>
 

I have set it up so that the blog name is included at the end of each HTML page title. If you are not happy with this then the following line of coding needs to be edited in each section. You could reverse the order, or you could drop the trailing blog name entirely.

<title><?php echo $my_title ?> | <?php bloginfo(‘name’); ?></title>
 

I have it set up so that only the first page of the home page / front page / main page is indexed. Then every page of each page, post, tag, category, and archive is indexed.

If you do not want tags to be indexed, for example, then simply delete the entire tags section which would look as follows.

<?php /*   Tags   */ ?>
<?php } elseif (is_tag()  && is_paged() ) { ?>
<?php $my_title = single_cat_title(”, FALSE); ?>
<?php $my_title = trim($my_title); ?>
<title><?php echo $my_title; ?><?php echo $random_string = chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)) . chr(rand(48,57)); ?>  | <?php bloginfo(‘name’); ?></title>
<?php } elseif (is_tag()) { ?>
<?php $my_title = single_cat_title(”, FALSE); ?>
<?php $my_title = trim($my_title); ?>
<title><?php echo $my_title; ?> Tag | <?php bloginfo(‘name’); ?></title>
 

You have just replaced the All for One SEO plugin.

Once you have edited the PHP elseif statement the way that you you want it to look, then paste it into the header.php template. Use the theme editor to update it by clicking on the Update File button. If for some reason, your changes fail to work then you will have to restore the header.php template with the good copy that you had saved before any changes were made.




Author: John H.Gohde









You can leave a comment, or trackback from your own site.



Then help our blog by linking to it. Simply copy and paste the code below into your website (Ctrl+C to copy)

It will look like this: Customizing Meta Tags in Wordpress


Digg It  Add To Delicious  Stumble This  Add to Technorati





2 Responses:


  1. Customizing Meta Tags in Wordpress | John H. Gohde Unleashed – Wordpress Plugins Says:

    [...] here to read the rest: Customizing Meta Tags in Wordpress | John H. Gohde Unleashed | More Categories: post plugin wordpress Tags: background-information – category [...]


  2. Customizing Meta Tags in Wordpress | John H. Gohde Unleashed | www.kotihost.com Says:

    [...] this link: Customizing Meta Tags in Wordpress | John H. Gohde Unleashed Share and [...]



Leave a Comment

 

Menu

» Customizing Meta Tags in Wordpress




Most Popular Posts

  1. Virus Checkers Are Dangerous
  2. Dead Computers Cannot Be Rejuvenated
  3. Threatfire is Perfect

 

 

Subscribe

Meta


Recent Posts

  1. Added Breadcrumb Navigation to Blog
  2. All in One SEO
  3. Always Keyword Stuff Intelligently

Copyright (C) 2008 - 2010 by John H. Gohde
All Rights Reserved.
Email | Site Map | Advanced Search