Whether in haste or just laziness, many times the meta description tags are not added to a page. This happens a lot when a company pays a (cheap) web designer to build their site, but the designer has no clue about SEO. Not having a meta description tag isn’t a deal breaker, but if you want to rank, and you want people to click on your rankings, you need to have them.
If you’ve been hired to do some SEO for one of these clients, I’ve got a nice little script that you can use to help you identify the pages without descriptions.
Part One: Getting all the pages to display a description tag
If you’re lucky, the designer built the site in a way that the header is it’s own file, usually called something like header.inc or header.php. This file houses the top HTML tags, the title tag, any javascript, CSS links, and of course the meta tags. Having one header file is great if you’ve got a top nav menu that you want to be the same across an entire site, or if you just want easier ways to identify your files.
The problem with one header file is that you can’t really hard-code the meta description tag, because then it’ll be the same across the entire site. In reality, every page on your site needs its own unique description. So how can you do this with one header file? Easy. Turn the tag into a variable.
<meta name=”description” value=”We offer the best widgets in the entire St. Louis area…”>
becomes
<?php $pagedesc=”We offer the best widgets in the entire St. Louis area…”; ?>
<meta name=”description” value=”<?php echo $pagedesc; ?>“>
Now that we’ve changed the description to a variable, we can play around with it a bit. First, we need to open a page (lets call it services.php – our services page) and add it’s custom header.
(top of services.php)
<?php $pagedesc=”We offer widget repair services in our fully equipped widget shop…”;
include ‘header.php’; ?>
By putting the pagedesc before the include, it will already have it set for that particular page. Now all we have to do is make one more change to the header file and we’re set with the description tag for every page.
<?php if (!$pagedesc) { $pagedesc=”We offer the best widgets in the entire St. Louis area…”; } ?>
<meta name=”description” value=”<?php echo $pagedesc; ?>”>
Now if a page doesn’t have a description, we can give it one. Albeit generic, at least we’re moving in the right direction, and the search engines will be happier and display a little better description of our site.
Part Two: Setting an alert for your pages that don’t have a description
This can be a pain, particularly if you’re taking over someone elses work, and you are perhaps a bit cloudy on the entire site layout.
What we’re going to do is simply add a few more lines to the header that will email us every time someone visits a page that doesn’t have a description. The email will have the link to the page, and we can then go in and start to fix these pages as they are visited.
(header.php)
<?php if (!$pagedesc) {
$page=”http://www.domain.com”.$_SERVER['PHP_SELF'];
$message=”The following page is missing a description:
Page: $page\n”;
mail(“will@willhanke.com”, “Page missing Meta Description”, $message);
$pagedesc=”We offer the best widgets in the entire St. Louis area…”;
} ?>
<meta name=”description” value=”<?php echo $pagedesc; ?>”>
Now I know there are programs out there that can do some fancy searches and spit out a list of all pages in violation of the page description tag, but since it’s not a deal breaker for web ranking, I like this method. It emails you, and when you have time you can get in there and update the pages that are (at least) being visited.