Make WordPress SEO friendly with a proper title and description tags

Someone said something like "if you're ever been charged of SEO, you've bee cheated". Having the basics right, gets you long way.

This post shows you how to use post excerpt and custom fields as description meta tag. And how to use the title right.

There are a lot of SEO plugins out there, you can use one of them, they do pretty much the same job.

Title

For this post the title looks something like make-wordpress-seo-friendly-with-a-proper-title-and-description-tags — clubmate.fi. It’s important that it shows the title of the page first rather than the site name. The title of the page is important, thats what people are searching for. See below how to do that.


1) {
	echo ' — page '. $paged; }
?>

Source

It can be included easily to keep header.php clean.


<?php include "adds/title.php"; ?>

Description meta tag

It’s this one:



This is what Google shows under the title of the site in the search results. So, it makes sense to slap the beginning of the site content there (Google starts cutting it after 150-160 characters).

Here’s how to do that.


global $post;
$cont = strip_tags($post->post_content); //Strip markup
$cont = str_replace(array("\n", "\r", "\t"), ' ', $cont); //Change line breaks and tabs to single space
$cont = str_replace(array('"',"'"), '', $cont); //Strip " and '
$cont = substr($cont, 0, 160); //Set the length to 160

Put that into a separate file and call it description.php, and include it in the header, like this.


">

What if you have vital data in custom fields? No worries, they’re easy to add. I’m using WPAlchemy metabox helper class here, but you can use normal custom fields as well.


global $custom_metabox; //Needed for the metabox class
$custom_metabox->the_meta(); //Needed for the metabox class
$what   = $custom_metabox->get_the_value('what'); //Get the values
$what_i = $custom_metabox->get_the_value('client');
$status = $custom_metabox->get_the_value('status');
$link   = $custom_metabox->get_the_value('link');

//Same as in the above example
global $post;
$cont = strip_tags($post->post_content);
$cont = str_replace(array("\n", "\r", "\t"), ' ', $cont);
$cont = str_replace(array('"',"'"), '', $cont);
$cont = substr($cont, 0, 160);

//Echo them out to your liking, in this case separated with spaces
echo $what . ' ' . $status . ' ' . $client . ' ' . $link . ' ' . $cont;

One more thing. The description most likely should be different on archive page and home page than on a single post page. Then you can just conditionally add different bits to your liking.


//Front page
if (is_front_page()) :
	
    global $post;
    $cont = strip_tags($post->post_content);
    $cont = str_replace(array("\n", "\r", "\t"), ' ', $cont);
    $cont = str_replace(array('"',"'"), '', $cont);
    $cont = substr($cont, 0, 160);

    echo get_bloginfo('title') . ' ' . get_bloginfo('description') . $cont;

//Archive, no content here
elseif (is_archive()) :

    echo get_bloginfo('title') . ' ' . get_bloginfo('description');

//Page or single post, using the custom fields and post content
elseif (is_page() || is_single()) :  
    //Custom fields
    global $custom_metabox;
    $custom_metabox->the_meta(); //Call this once
    $what   = $custom_metabox->get_the_value('what');
    $status = $custom_metabox->get_the_value('status');
    $client = $custom_metabox->get_the_value('for_long');
    $link   = $custom_metabox->get_the_value('link');

    //Content of the post
    global $post;
    $cont = strip_tags($post->post_content);
    $cont = str_replace(array("\n", "\r", "\t"), ' ', $cont);
    $cont = str_replace(array('"',"'"), '', $cont);
    $cont = substr($cont, 0, 160);
    





    //Echo out
    echo $what . ' ' . $status . ' ' . $client . ' ' . $link . ' ' . $cont;

endif;

In SEO the actual content of the post is the most important thing, of course. With out it, none of this makes any difference.

Club-Mate, the beverage → club-mate.fi