Using PHP to Create Relevant Title Tags in osCommerce Websites

If you use osCommerce for your site’s e-commerce, and you’re not happy with the quality or quantity of visitors your site receives, keep reading. Though osCommerce provides some excellent features, its weaknesses could be getting in the way of giving you the number of visitors and conversions you expect. Fortunately, there’s a solution, hidden in something as simple as a title tag.

osCommerce is the most popular online e-commerce solution. The primary reason for this popularity is its nature as open source software; it can be used for almost no cost compared to other online e-commerce software.

osCommerce runs on PHP and MySQL, again an open source solution. Despite its popularity, it possesses a significant weakness. The default page title generated by the osCommerce is highly unfriendly to both site visitors and the search engines, particularly the most popular one: Google.

A high percentage of site conversion and website marketing success is primarily due to the correct use of title tag element <title> ….</title>  

This tutorial proposes a solution that allows an osCommerce web developer to generate unique and relevant title tags using only PHP. This eliminates the need to hire or consult an SEO on-site — work which can be tremendously costly.  

Specification of Page Title for Search Engine Marketing Success

Very popular search engines like Google advise  webmasters under their technical guidelines to include accurate and descriptive titles for their web pages. It is essential that the page title should be:  

  • Preferably 65 characters. Exceeding this limit is permissible, but you should make sure your important keywords are prominent within the first 65 characters.

  • Perfectly relevant to the page topic. Users of osCommerce often make the mistake of creating misleading and inappropriate page titles.

    For example: if the product name on a page is "Widgets XYZ," the page title should be the same as the product name. Or in other cases, if the category is "Large Widgets," the page title should be the same as the category name.

  • Avoid having the same title tags in almost all product names and categories. Duplicate title tags are strongly discouraged for search engine optimization because they can affect the rankings of the product pages and cause dilution of the relevant pages.

You can do a rough check of your existing website to see if there are problems with duplicate titles. The best tool to use is http://www.google.com/

Type this in the search box (without including the www or http):

site:thisisyourdomainname.com

After pressing "search" in Google, you will see whether your indexed pages are having serious problems with duplicate titles. For example, below is a sample screen shot of a website having some issues with duplicate titles:

<Insert duplicate title.jpg here>

As you can see, most of the indexed pages have the same title, "osCommerce," which is completely unrelated to the page topic. This affects the site’s search engine marketing effort and will confuse potential visitors.

{mospagebreak title=osCommerce Web Template Files and Page Title Naming}

In order to successfully create appropriate names for the page title in an osCommerce website, you must edit two important files and the corresponding important pages of the website.

  1. Index.php - This is the most important template file in osCommerce. This template is responsible for generating titles for the home page and category pages. 

  2. Product_info.php – This template is responsible for naming the title tag for the product pages. This template can cause very serious problems. In a giant osCommerce site with thousands of products, using this template unmodified also means there are thousands of pages with the same titles.

Other pages are not as important as the two above, but it is very important that they also use unique and relevant page titles. The pages are found in the main site navigation menu. For example:

  • New Products page: products_new.php

  • Special offer page: specials.php

  • Contact us page: contact_us.php

  • Privacy Policy page: privacy.php

You should also modify other pages that are commonly found if you have them, such as the terms and conditions page, sitemap page and "About Us" page.

We’ll start with the index.php since this is a very important file. By default, the title tag PHP script found in the index.php is:

<title><?php echo TITLE; ?></title>

This is not enough. It will produce a home page title equal to the store owners’ name, or the name of the store, which will not help with search engine optimization efforts.

It gets worse. The page title on the categories pages will be the same as the one on the home page and even the product pages! 

This can confuse visitors shopping your online store powered by osCommerce; even search engine bots like Googlebot will have problems sorting things out. Your site will be very hard for them to understand, and in return, since you confused Googlebot, you will not be rewarded with great rankings and traffic.

{mospagebreak title=Proper Page Title Naming for the Home Page and Categories}

General warning: Before doing any on-site work, do not forget to back up your original files.

Now that we know the basic files that need to be edited to give your site the most relevant and unique page titles, we will come up with a good strategy to change those titles into something we want.

  1. The home page Title should be an SEO-optimized title tag. 

  2. We can use the category variable cPath in the URL to fetch the correct category name in the MySQL database. As long as the URL is given, we can use PHP to analyze the URL, grab the category ID number, communicate to the MySQL database and finally grab the corresponding category name.
  3. The appropriate product category name should then be returned as the category page title.

  4. The same technique will be applied to the product pages. The cPath ID number corresponds to the product ID with the corresponding product name in the MySQL database.

 

PHP script for producing unique titles for the home page and category pages (actual script in blue):

<head>

<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">

<?php

$optimizedurl=$_SERVER["REQUEST_URI"];

if (preg_match("/cPath/i", $optimizedurl))

{

//this is a category page, extract the category name

$location1=(strpos($optimizedurl,’cPath’));

$start= $location1 + 6;

$categoryextracted=substr($optimizedurl,$start,2);

$result = mysql_query("SELECT `categories_name` FROM `categories_description` WHERE `categories_id`=’$categoryextracted’")

or die(mysql_error());

$row = mysql_fetch_array($result)

or die("Invalid query: " . mysql_error());

echo "<br />";

$titletag = $row['categories_name'];

}

else

//this is the root page

{

$titletag = ‘Put your SEO optimized title tag here for the homepage';

}

?>

<title><?php echo $titletag ?></title>

Let me explain how the PHP script above will get the appropriate page title. It starts with

$optimizedurl=$_SERVER["REQUEST_URI"];

This script will get the URL of the page and store it to a variable. Note that $_SERVER["REQUEST_URI"] is not perfectly compatible with Windows Server, and there are things that need to be adjusted; explaining them is beyond the scope of this tutorial. However, you can read it here:

http://www.php.net/reserved.variables

Now, since the index.php will cover both the home page and the category pages, we need to determine whether the URL analyzed by PHP is for a category page or the root URL. This script will provide the answer:

if (preg_match("/cPath/i", $optimizedurl))

{

Category pages contain cPath in the URL, and by using the  preg_match function, we can test to see if it contains this variable.

If it is a category page, the next job of the script is getting the category ID, which will be used to pull out the category name in the MySQL database:

//this is a category page, extract the category name

$location1=(strpos($optimizedurl,’cPath’));

$start= $location1 + 6;

$categoryextracted=substr($optimizedurl,$start,2);

$result = mysql_query("SELECT `categories_name` FROM `categories_description` WHERE `categories_id`=’$categoryextracted’")

or die(mysql_error());

$row = mysql_fetch_array($result)

or die("Invalid query: " . mysql_error());

echo "<br />";

$titletag = $row['categories_name'];

The combination of strpos and substr will extract the category ID from the URL.

For example:

http://localhost/osc/index.php?cPath=4&osCsid=2a003844f541432aa794b92c2ece050d

The category ID in the above URL is the value of the cPath variable, which is 4.

The rest of the above script’s purpose will be to query the database in order to extract the category name.

{mospagebreak title=Proper Page Title Naming for the Product Pages}

For the Product_info.php, the following is the recommended script:

<?php

$optimizedurl=$_SERVER["REQUEST_URI"];

$location1=(strpos($optimizedurl,’products_id’));

$start= $location1 + 12;

$productidextracted=substr($optimizedurl,$start,2);

$result = mysql_query("SELECT `products_name` FROM `products_description` WHERE `products_id`=’$productidextracted’")

or die(mysql_error());

$row = mysql_fetch_array($result)

or die("Invalid query: " . mysql_error());

echo "<br />";

$titletag = $row['products_name'];

?>

<title><?php echo $titletag; ?></title>

To implement the following recommendations, find this piece of code in the default affected templates:

<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">

<title><?php echo TITLE; ?></title>

Replace it with the modified PHP script. For the product_info.php the above lines will now become:

<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">

<?php

$optimizedurl=$_SERVER["REQUEST_URI"];

$location1=(strpos($optimizedurl,’products_id’));

$start= $location1 + 12;

$productidextracted=substr($optimizedurl,$start,2);

$result = mysql_query("SELECT `products_name` FROM `products_description` WHERE `products_id`=’$productidextracted’")

or die(mysql_error());

$row = mysql_fetch_array($result)

or die("Invalid query: " . mysql_error());

echo "<br />";

$titletag = $row['products_name'];

?>

<title><?php echo $titletag; ?></title>

To be truly effective, revise the title tag PHP script in all important templates such as index.php, product_info.php, and the main pages in a typical osCommerce website navigation menu.

You can find more osCommerce tips and tricks here: http://www.php-developer.org/

[gp-comments width="770" linklove="off" ]

antalya escort bayan antalya escort bayan Antalya escort diyarbakir escort