You are here:  » Meta tags in PT 15/09A


Meta tags in PT 15/09A

Submitted by marco@flapper on Thu, 2016-04-21 14:20 in

Hi,
How can I add meta description and tags for index/frontpage? And how can I alter the meta keywords tag for search results/productpages so that it uses the category of the product?

A. Add meta description/tags to index/frontpage
I found: http://www.pricetapestry.com/node/5160 but I guess it is different in version 15/09?

B. Alter meta keywords tag in productpages
Can this be done?

Submitted by support on Thu, 2016-04-21 14:39

Hi Marco,

RE: A;
Node 5160 is current for 15/09A - as long as you set the $header["meta"]["description"] and $header["meta"]["keywords"] before the call to html/header.php your custom home page meta tags will be included in the header.

RE: B;
Description and keywords meta tags are set at lines 70-72 of products.php as follows;

  $header["meta"]["description"] = translate("Price search results for")." ".$product["products"][0]["name"];
  $header["meta"]["keywords"] = $product["products"][0]["name"];

Category can be included by way of $product["products"][0]["category"] - but for best results should be included conditionally only if set, so for example, to append the category in brackets to the description, and as an additional keyword, REPLACE the above as follows;

  $header["meta"]["description"] = translate("Price search results for")." ".$product["products"][0]["name"];
  if ($product["products"][0]["category"])
  {
    $header["meta"]["description"] .= " (".$product["products"][0]["category"].")";
  }
  $header["meta"]["keywords"] = $product["products"][0]["name"];
  if ($product["products"][0]["category"])
  {
    $header["meta"]["keywords"] .= ",".$product["products"][0]["category"];
  }

For search results pages, let's say you wanted to make a meta description of "Search results for ..." and a meta keywords of the query plus the category of the first result, in search.php look for the following code at line 503:

  $header["title"] = $q;

...and REPLACE with:

  $header["title"] = $q;
  if ($resultcount)
  {
    $header["meta"]["description"] = "Search results for ".$q;
    $header["meta"]["keywords"] = $q;
    if ($searchresults["products"][0]["category"])
    {
      $header["meta"]["keywords"] .= ",".$searchresults["products"][0]["category"];
    }
  }

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by marco@flapper on Fri, 2016-04-22 07:27

RE: A;
Works nicely.

RE: B;
I was wondering if $header["meta"]["keywords"] = $product["products"][0]["name"]; could be modified so that it only uses the first word in it as keyword?

Submitted by support on Fri, 2016-04-22 07:30

Hi Marco,

Sure - in place of:

   $header["meta"]["keywords"] = $product["products"][0]["name"];

...have a go with:

   $p = explode(" ",$product["products"][0]["name"]);
   $header["meta"]["keywords"] = $p[0];

Cheers,
David.
--
PriceTapestry.com

Submitted by marco@flapper on Fri, 2016-04-22 07:50

Works brilliantly.