Ecommerce Templates > Search engine friendly > Dynamic title and meta description tags - PHP Version

Dynamic title and meta description tags - PHP Version

search engine friendly

It is possible to dynamically generate the title and meta description tags for your categories, product and product detail pages. Not only are they dynamically generated but you can also add you own unique information such as company name to the title tag. In version 6.4 you can also set the title and meta description tag through the product and category admin pages on a product by product basis. The set up details are outlined below:

The pages you are going to want to change are categories.php, products.php and proddetail.php

Open each of these in turn and go to HTML view. About halfway down the page you should see a bunch of "include" files, something like this...

<?php include "vsadmin/db_conn_open.php"?>
<?php include "vsadmin/inc/languagefile.php"?>
<?php include "vsadmin/includes.php"?>
<?php include "vsadmin/inc/incfunctions.php"?>
<?php include "vsadmin/inc/incproducts.php"?>

You will want to delete the first one, the db_conn_open.php line.

Then, at the very top of the file before the first <html> tag you should already have a couple of lines of code. Now add the db_conn_open line along with the metainfo.php include line like this...

<?php
session_cache_limiter('none');
session_start();
ob_start();
include "vsadmin/db_conn_open.php";
include "vsadmin/inc/metainfo.php";?><html>

Now repeat this with each of the 3 files categories.php, products.php and proddetail.php

categories.php title tag

If you want to use the title you have added in the category admin page

Category page title

...use the following for the title on categories.php

<title>Bob's widget store: <?php print $pagetitle;?></title>

If you are not using the Page Title Tag feature you may want to use the following instead which will show the category name in the title

<title>Bob's widget store: <?php
if($topsection != "") print $topsection . ", ";
print $sectionname?></title>

categories.php meta description tag

Below the title add the following....

<meta name="Description" content="<?php print str_replace('"','&quot;',$sectiondescription)?>">

If you are using the meta description feature in the admin category page

Meta description

That is what will appear on categories.php. If you are not using that feature, the section description will be used instead.

Advanced categories.php settings

Instead of using the above, copy and paste the following lines into vsadmin/includes.php (changing the text for your own)

$GLOBALS['sitenamelong']='The name of your site goes here (around 50-60 characters and unique)';
$GLOBALS['rootcategorytitle']='The page title to appear on the main categories.php page (around 50-60 characters)';
$GLOBALS['rootcategorydescription']='The page meta description to appear on the main categories.php page (around 160 characters max)';

Replace the title and meta description tags on categories.php with the following

<title><?php
if(!empty($pagetitle)) {print $pagetitle;}
else if(!empty($sectionname)) {print $sectionname . ' | ' . $sitenamelong;}
else {print $rootcategorytitle;} ?></title>
<meta property="og:title" content="<?php
if(!empty($pagetitle)) {print $pagetitle;}
else if(!empty($sectionname)) {print $sectionname . ' | ' . $sitenamelong;}
else {print $rootcategorytitle;} ?>">

<meta name="Description" content="<?php if(!empty($sectiondescription)) {print str_replace('"','&quot;',$sectiondescription);} else {print $rootcategorydescription;} ?>">

Make sure you test the results by viewing source on your category and sub-category pages.

products.php title tag

If you want to use the title you have added in the category admin page

Category page title

...use the following for the title on products.php

<title>Bob's widget store: <?php print $pagetitle;?></title>

If you are not using the Page Title Tag feature you may want to use the following instead which will show the category name in the title

<title>Bob's widget store: <?php
if($topsection != "") print $topsection . ", ";
print $sectionname?></title>

products.php meta description tag

Below the title add the following....

<meta name="Description" content="<?php print str_replace('"','&quot;',$sectiondescription)?>">

If you are using the meta description feature in the admin category page

Meta description

That is what will appear on products.php. If you are not using that feature, the section description will be used instead.

Advanced products.php settings

Instead of using the above, copy and paste the following lines into vsadmin/includes.php (changing the text for your own)

$GLOBALS['sitename']='The name of your site goes here (around 50-60 characters)';
$GLOBALS['allpagestitle']='The page title to appear on the main products.php page (around 50-60 characters)';
$GLOBALS['allpagesdescription']='The page meta description to appear on the main products.php page (around 160 characters max)';

Replace the title and meta description tags on products.php with the following

<?php $pno = (isset($_GET['pg']) && is_numeric($_GET['pg'])) ? (int)$_GET['pg'] : 1; $pagenumber = ' page ' . $pno; ?>
<title><?php
if(!empty($pagetitle) && $pno == 1) {print $pagetitle;}
else if(!empty($pagetitle) && $pno != 1){print $pagetitle . $pagenumber;}
else if(!empty($sectionname) && $pno == 1) {print $sectionname . ' | ' . $sitename;}
else if(!empty($sectionname) && $pno != 1) {print $sectionname . ' | ' . $sitename . $pagenumber;}
else if($pno == 1) {print $allpagestitle;}
else {print $allpagestitle . $pagenumber;} ?></title>

<meta name="Description" content="<?php
if(!empty($sectiondescription) && $pno < 2) {print $sectiondescription;}
else if(!empty($sectiondescription) && $pno > 1) {print $sectiondescription . ' ' . $pagenumber;}
else if($pno < 2) {print $allpagesdescription;}
else {print $allpagesdescription . ' ' . $pagenumber;} ?>">

Make sure you test the results by viewing source on your product pages.

proddetail.php title tag

If you want to use the title you have added in the product admin page...

Category page title

...use the following for the title on proddetail.php

<title>Bob's widget store: <?php print $pagetitle;?></title>

If you are not using the Page Title Tag feature you may want to use the following instead which will show the product name, category name and product id in the title

<title>Bob's widget store: <?php
print $productname . ", " . $sectionname . ", " . $productid;
?></title>

You might not want to include the product ID, in which case you can use...

<title>Bob's widget store: <?php
print $productname . ", " . $sectionname;
?></title>

proddetail.php meta description tag

Below the title add the following....

<meta name="Description" content="<?php print str_replace('"','&quot;',$productdescription)?>">

If you are using the meta description feature in the product admin page

Meta description

That is what will appear on proddetail.php. If you are not using that feature, the product description will be used instead.

Note If you are using the category identifier feature or extensionless URLs you will also need to place the includes.php line at the top of the code like this

<?php
session_cache_limiter('none');
session_start();
ob_start();
include "vsadmin/db_conn_open.php";
include "vsadmin/includes.php";
include "vsadmin/inc/metainfo.php";?><html>

Multiple language set up

If you are using the multiple language set up then you will need these include <html> tag:

<?php include "vsadmin/db_conn_open.php" ?>
<?php include "vsadmin/inc/languagefile.php"?>
<?php include "vsadmin/includes.php" ?>
<?php include "vsadmin/inc/incfunctions.php" ?>
<?php include "vsadmin/inc/metainfo.php" ?>

...making sure they are not duplicated later in the code.

NOTE
There are some advanced settings available here in the Dynamic Title / Meta Description thread of the support forum.

Top of page

More search engine friendly features from Ecommerce Templates

Top of page