HTML Meta Tags – A tutorial in writing a WordPress Plug-in



Introduction

This article is the first in a series of tutorials about writing simple WordPressµ Plug-Ins for your blogs. Although there are many, many plug-in tutorials available to you on the internet, this tutorial is focused on a specific task; How to add HTML meta tags to a theme header when the theme is used across multiple blog-based sites, such as when using WordPressµ.

The problem arises when the same theme is used by multiple sub-domain sites (URLs) within the multi-user framework of WordPress. You cannot simply place the desired meta tags in the header.php file because those parameter values would apply to every site that references that theme, thereby defeating the purpose of unique meta tags. Note that meta tags common across sites may be included in the document (header.php file) head section without conflict.

The Wayback Machine

Notice that we are discussing tag placement within the header of a document. Why is it called a document? Why is there a document header? Without getting too mundane, the interweb, in it's early life, was a means by which authors could share and reference information. The architecture of this information was constructed in the same manner as their printed documents were written. After all, what else did they have to reference? So, it came to be called a document -- Nowadays commonly referred to as pages. The two terms are interchangeable.

...the good thing about standards is there are so many to choose from...

The invention of certain document content properties was required in order to isolate specific articles written by the same author, maybe about a similar subject, even stored at the same location. This information was stored in a header section of each document. These document content properties are still in place today, although, some may not be as important as previously conceived. Each author(-ity) has their own preferences as to which are and are not important.

The basic old-time web site consisted of an index page, where by all other documents could be listed. Then, each document was stored and contained certain document-centric information. The use of this construction allowed users to search for documents by relevance. For example, an astronomer searching for documents relating to eclipses would receive all documents pertaining to both solar and lunar eclipses. Conversely, an astronomer searching for lunar eclipses would not receive the documents relating to solar eclipses. Sound familiar? You should know that search engines still work the same way today, although much more information is disseminated due the evolutionary complexity of these documents. I won't get into discussing the document markup tags, SGML and HTML, as that is for other sites.

Common meta tags

The content properties of a document (let's loosely call them, tags) are too numerous to discuss here. There are, however, a common handful in place today that are used to describe the current document. The following list is by no means complete. For the purpose of this article, however, it is. You may choose to omit or include other tags as you see fit.


Table 1. Common Meta Tags
Tag Description
Author This specifies the author of this document. The founding fathers were brilliant, weren't they?
Robots This specifies the dissemination of the document by search engines.
Copyright This defines the copyright information for the document.
Distribution This defines how this document is intended to be distributed.
Language This provides a list of supported document languages.

I included the Distribution meta tag here simply to illustrate the original concepts and purpose of document properties. Although no longer generally used, it's purpose was to signify whether a document was meant for internal use only or distributed globally. Nifty, huh? Since almost all documents written for the web are intended to be distributed globally, there is little need to include this tag. I do, simply because I'm old-school. ...and anal.

These common tags are static for the web site as a whole. That means that regardless of the documents viewable from the web site, each document has the same information defined for these tags (I'll discuss dynamic tags in a later article.) This is where the problem rears it's ugly head.

Unique meta tags

There are specific tags that must be unique to each web site document. When you implement a framework like WordPressµ, where more than one web site can use the same document theme, WordPress uses a common header file that is loaded with each and every document, rather than having individual header files for each web site. There needs to be a mechanism in place to define those unique, or custom, meta tags. The MU Meta Tags plug-in solves that problem.

For this tutorial, I will be using the following four meta tags. You can, of course, add or remove meta tags as you deem necessary for use within your environment. I will recommend that you use the existing meta tags as written until we complete this project, at which time, it will be much simpler to make your desired changes because you will have a complete picture rather than a segmented view.

Table 2. Customizable Meta Tags
Tag Description
verify-v1 This specifies the Google verification code for this specific web site.
Abstract This is a brief abstracted definition of the document contents. This is similar to, but not necessarily the same as, the description tag.
Description This is a more detailed description of the document contents.
Keywords This is a comma separated list of words, that should be used throughout a document, for the purpose of indexing by search engines.

Note: I am in no way saying that these are the only meta tags that should ever be used. In fact, there are many meta tags that you should use depending upon your site content. That is an exercise left to you.

You can see from this list that it is important to have unique definitions for these document properties. Each web site must contain a description, keyword list, and if elected, a verification code that is unique from other web sites. You should also know that in some cases it is even desirable to have unique meta tags for each document within a specific site. But that is for the next article in this series. In the meantime, WordPress saw fit to recommend that theme designers include a cool little gizmo in the header.php file called, wp_head().

Note: If your theme does not include the call to wp_head(), simply insert the following code into your header.php file at te desired location and this plug-in will function as intended.

<?php wp_head(); ?>

Basically, the wp_head() acts as a placeholder that we can hook into. It's purpose says, "Hey! Does anyone need to process information here before I finish?" What we will use this for is to interrupt the normal output of the header, insert our meta tag data, then let the header output complete. This is the purpose of a "hook". It allows us to inject our desired function and then return to the normal program processing.


Pages: 1 2 3

Leave a Reply

You must be logged in to post a comment.


Popular Posts

Sponsor Ad Management User Guide

The cd_ad_sponsor plug-in was written to manage the sponsor ads that can be presented with

A WordPress Sponsor Ad Management Plug-In

I wrote the WordPress Sponsor Ad Management Plug-in to use within the WordPress and WordPr

Quote of the day plugin

The Quote Of The Day plug-in manages quotes displayed on your WordPress or WordPressµ

Quote Of The Day
This is a quote with a link.