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.
Published by Rebecca Mastey
Rebecca has been writing for fun and profit for the past 5 years and specializes in politics, technology, parenting and cuisine. Presently, she is researching and writing about sustainable technologies. View profile
- The Demand for Spanish-Language Cancer Information Sites SkyrocketsImagine finding out that you have cancer, trying to get information, and not being able to read the bulk of the information that is written. That's the experience that many Spanish-language web users have as the numbe...
- Are You Looking for Information on This Fall's Hottest Television Shows?It's that time of year again, the kids have returned to school. They have limited time to enjoy the entertainment on television, so they want as much information as they can find about the new season. Zap2It has a gu...
Your Best Offer to Your Customers is InformationInformation marketing pulls over and over and works well. "How -to" information is the most popular means of information marketing.
- What Are META Tags?
- How to Use HTML Meta Tags
- Search Engine Optimization: Phase Two - Relevant Keyword Research, the Search Engi...
- How Public Should Public Information Be?
- Hundreds Have Bank Account Information Stolen in Orange County
- The "Information Dissemination" Approach to Internet Advertising for Mortgage Lenders
- More Valuable Information for Success from Internet Business Experts
- How meta description can help your site
- Use of Title for bookmarking
- Use of tags for social bookmarking sites





4 Comments
Post a CommentThank You soo Much. Such a simple piece of script and I was just about banging my head against the wall. Thanks A Million!!!
@maximo
You need to specify specific meta tags on a page by page basis. $metaTags, for example, might be "cat, dog, mammal" on one page, but "chicken, pheasant, poultry" on another. Since each will be declared on an individual page, you can change them as you go while keeping the header static across the site.
I'm sorry, I may sound dumb but it seems
to me that the above script would echo
the same exact meta on every page.
How can you have different content displayed if you don't define it and tell php what to use where?
Thank you thank you thank you thank you!! I've been trying to make this happen for years and your post made it much less complicated than I've seen on other Blogs! Soooo appreciate it!! Cheers!