You are here:  » Meta Tag Control

Support Forum



Meta Tag Control

Submitted by Eddie on Wed, 2006-11-22 19:34 in

I want to be able to do several things:

1. I want to be able to add in default text for the index page META tags

2. In the Brand/Category/Merchant pages I also want to be able to specify the META tags

3. On the product pages I want to be able to put not only the product name (as we have presently), but the product price (from £ xxx)

I was also wondering if it is possible to have the product names for any RELATED results displayed on the product page included in the KEYWORD tag.

It would be useful if 1 and 2 could be administered from the config file. Sort of like default META info....

Thanks

Eddie

Submitted by support on Thu, 2006-11-23 08:30

Hi Eddie,

1/2.
For index page meta tags, you need to add the following code before the call to require("includes/header.php");

  $header["meta"]["description"] = "Your description here";
  $header["meta"]["keywords"] = "Your, Keywords, Here";

You can do exactly the same on the Brand/Category/Merchant index pages; but remember that the brand and category result pages are actually served up by search.php; which is where you will need to add the meta tag code.

In search.php, you can add similar code to the above - again, just before require("includes/header.php") - but in this case you have access to the variables that contain the query information.

In the case of a normal search, the query is in $parts[0]. For a category search, $parts[0] contains "category", and the category name is in $parts[1] (and similarly for "brand") - so you need to decide how you want to use these variables to construct your meta tags.

If you just want the keyword tag to contain the category or brand name, you could do this:

  if ($parts[1])
  {
    $header["meta"]["keywords"] = $parts[1];
  }

...you could take that further and take advantage of the fact that $parts[0] contains "category" or "brand" and use it to construct a description:

  if ($parts[1])
  {
    $header["meta"]["keywords"] = $parts[1];
    $header["meta"]["description"] = $parts[0]." search results for ".$parts[1];
  }

3.
In products.php, the meta tags are set round about line 53 in the distribution. If you've modified that file, just search for $header["meta"] to find them.

At this point, the price of the product will be in $product["products"][0]["price"]. To incorporate this into the description you could use something like this (based on code that already exists):

  $header["meta"]["description"] = translate("Price search results for")." ".htmlentities($q,ENT_QUOTES,$config_charset). " lowest price ".$config_currencyHTML." ".$product["products"][0]["price"];

To add the related product name as keywords; add this code lower down the file; again just before the call to require("html/header.php")...

  foreach($searchresults["products"] as $related)
  {
    $header["meta"]["keywords"] .= ", ".$related["name"];
  }

Finally, if you wanted to make the meta tags on the index and any other pages configurable; all you need to do is add a suitable variable to your config file; for example:

  $config_metaDescriptionIndex = "Your, Description, Here";

..and then in index.php

  $header["meta"]["description"] = $config_metaDescriptionIndex;

Hope this helps,
David.

Submitted by Eddie on Thu, 2006-11-23 09:25

David,

Thanks for that.

I have added all of tha baove and it works great.

I am also trying to add the price to the TITLE tag which is this bit

.$product["products"][0]["price"]

Can you point me as I aint getting it

Eddie

Submitted by support on Thu, 2006-11-23 11:11

Which file have you included that in?

That code is only valid in products.php, and must come after the main block of code. can you paste the whole line of code that you're using...

Cheers,
David.

Submitted by Eddie on Thu, 2006-11-23 11:50

David,

YThe code I have is not working at all - to the point where I have deleted it!

On products.php in the title tag I simply want to include the product price (as well as the name).

Eddie

Submitted by support on Thu, 2006-11-23 11:57

Hiya,

Did you replace:

  $header["meta"]["description"] = translate("Price search results for")." ".htmlentities($q,ENT_QUOTES,$config_charset);

with...

  $header["meta"]["description"] = translate("Price search results for")." ".htmlentities($q,ENT_QUOTES,$config_charset). " lowest price ".$config_currencyHTML.$product["products"][0]["price"];

(removed a space between the currency and the price this time)

That should work, provided it goes in at exactly the same point in the code...

Cheers,
David.

Submitted by Eddie on Thu, 2006-11-23 12:56

David,

My fault I dont think I was clear! All the above is working fine.

I want to get the price on the Product page in to the TITLE tag

As on http://www.shopsort.co.uk/product/20-TFT-monitor-AL2021MS-25ms.html

*title*20 TFT monitor AL2021MS 25ms //BRAND HERE// //PRICE HERE// */title*
*meta name='keywords' content='20 TFT monitor AL2021MS 25ms, Calibration kit Eye One Display LT for monitors Easy Cam USB 20 VGA 13 M Webcam, Calibration kit Huey for monitors Acquisition case DVD Xpress DX2 USB 20, L20 1W 20 LCD Screen 8 ms Audio headset 550 DSP' /*
*meta name='description' content='Price search results for 20 TFT monitor AL2021MS 25ms lowest price £ 382.00' /*

I would also like (as example above) to get the brand in there.

Eddie

Submitted by support on Thu, 2006-11-23 13:29

Hi Eddie,

Exactly the same principal; you will the see where the title is set on the line before the meta description:

$header["title"] = $q;

So, if you want to get brand and price in there, do something like this:

$header["title"] = $q." ".$product["products"][0]["brand"]." ".$config_currencyHTML.$product["products"][0]["price"];

Cheers,
David.

Submitted by Eddie on Thu, 2006-11-23 14:04

David,

Thanks got that working ok.

Eddie

Submitted by Eddie on Mon, 2006-11-27 15:04

David,

iIs it also possible to gett eh product description in to the META desc' tag as well based on the above code?

Eddie

Submitted by support on Mon, 2006-11-27 17:21

Hi Eddie,

Sure - it's in the "description" key....

  $header["meta"]["description"] = translate("Price search results for")." ".htmlentities($q,ENT_QUOTES,$config_charset). " lowest price ".$config_currencyHTML.$product["products"][0]["price"]." ".$product["products"][0]["description"];

Cheers,
David.

Submitted by clickspace on Thu, 2008-02-21 20:23

Hi David,

I've been customising the meta data for the index, search results and product page but having problems getting this to work with my "searchcode.php" page which is used of course for custom content with search results.

The end of searchcode.php currently looks like this;

  $header["title"] = $q;
    $navigation["resultCount"] = $resultCount;
    $searchresults["numRows"] = database_querySelect($sql,$rows);
    $searchresults["products"] = $rows;
    foreach($searchresults["products"] as $k => $product)
    {
      if ($config_useRewrite)
      {
// modified
$searchresults["products"][$k]["productHREF"] = $config_baseHREF . "product/".tapestry_hyphenate($product["name"]).".html";
// end mod
      }
      else
      {
        $searchresults["products"][$k]["productHREF"] = "products.php?q=".urlencode($product["name"]);
      }
    }
  }
  $header["meta"]["description"] = "my desc here";
  $header["meta"]["keywords"] = "my keywords here";
?>

The relevant part of the source code output is simply blank...

<title></title>
</head>

Is this possible with the customised search page?

Cheers,
Steven

Submitted by support on Fri, 2008-02-22 08:50

Hi Steven,

This is because you will be including searchcode.php after html/header.php; which is where the meta tag HTML is generated.

To fix this, you will need to set $header["meta"]... etc. within the script that calls searchcode.php, so you would have:

  $header["meta"]["description"] = "my desc here";
  $header["meta"]["keywords"] = "my keywords here";
  require("html/header.php");

Hope this helps!
Cheers,
David.

Submitted by clickspace on Fri, 2008-02-22 09:32

Doh! I see now that I was trying to do things in an illogical order.

I now have on my custom page;

 $header["title"] = "my title";
  $header["meta"]["description"] = "my desc here";
  $header["meta"]["keywords"] = "my keywords here";
  require("html/header.php");

Which also means I can change the meta data per custom page just as it should be.

Thanks again,
Steven