Categories: Marketing

Use PHP to Generate Dynamic Meta Tags

While meta tags, titles and descriptions may not be the Holy Grail of search engine optimization, these HTML header sections can provide additional value to a correctly optimized page. Many websites, especially those with dynamic content, will benefit from assigning unique tags, titles and descriptions to individual pages. PHP simplifies this process and removes manual editing of individual pages.

Before approaching the PHP, familiarize yourself with the three items this tutorial discusses. At the top of your browser, you will see the Associated Content page title. For any given article, this is Article Title – Associated Content. This not only appears as the page title in search results, but lets users who use multi-tabbed browsing identify your page.

The description is a short block text, typically less than 160 characters, which is displayed with your title in search results. If this section is not completed, the search engine will select an appropriate section of text from the page to display.

Meta tags are, for all intents and purposes, useless for most modern search engines such as Google, Yahoo and Bling. Some search engines still use it while crawling pages and social bookmarking sites may rely on the tags to categorize your content or associate it with other websites.

To properly implement these items dynamically, ensure your pages use the .php extension rather than .html or .htm. Your pages must be in at least two parts. First, header.php, which will contain all the static information contained at the top of your page. These static items include logos and navigation buttons.

The rest of the content should be contained in an appropriately named .php file, such as index.php for the homepage or about.php for information on yourself, your company or your organization.

The following sections outline the necessary code. If you’re comfortable with PHP and want to get right to it, use this and you’ll be on your way. If you’re not comfortable with it, continue reading after these sections for explanations.

In the header.php file, place the following lines

– Your Webpage Name

In the index.php or pageTitle.php files, insert the following lines at the very top

$pageTitle = “My page title”;

$metaDescription = “My page description, less than 160 characters.”;

$metaTags = “a list, of appropriate, tags, separated with, commas”;

include(“header.php”);

?>

If you are unfamiliar with PHP, here is a quick primer. The $ + word combination denotes a variable. This is simply a short place holder for a longer section of text. There are exceptions to this rule for numbers, equations and other variables, but, for the purposes of this tutorial, remember to enclose the text in quotation marks.

By typing include(“header.php”), you are using the include function. This takes all the information from header.php (or any other included file) and places it exactly where you have called the function. It effectively merges the two documents when the page is loaded.

If you think of the two documents as merged, the variables will be declared at the very top of the page. The header file will then render, and echo, or print, the information inside the previously declared variables. Because the PHP itself is handled by the server, not your browser, your website will display the header information as plain text.

My page title – Your Webpage Name

Define $pageTitle, $metaDescription and $metaTags and include the header.php file at the top of every content page. Each page will display unique, dynamic meta information when it is loaded.

Karla News

Recent Posts

Littlest Pet Shop Portable Pets: Turtle – Toy Review

My niece and I have something in common. We both adore The Littlest Pet Shop…

3 seconds ago

Best Water Parks in Kansas City

On a hot summer day in Kansas City , nothing feels better than plunging into…

6 mins ago

Fukien Tea Bonsai

Fukien Tea or Carmona (genus) Macrophylla *sometimes mispelled microphylla, is a popular bonsai tree named…

12 mins ago

The Best Fishing Lures for Bass Fishing

In this article I'm going to list the best lures for bass fishing. The lures…

17 mins ago

Distortions of Wonderland Through the Criticism of Lewis Carroll

When exploring the meaning of a text the inevitable result is that the reader will…

22 mins ago

Risk Factors for Aortic Dissection

Aortic dissection is a rare though life threatening medical condition in which a tear develops…

28 mins ago

This website uses cookies.