You are here:  » SEO Tweaks - Page Titles & Meta Descriptions, H1 Tags & more


SEO Tweaks - Page Titles & Meta Descriptions, H1 Tags & more

Submitted by mlepisto on Tue, 2018-02-13 21:38 in

Hi,

I'm trying to figure out how to tweak some SEO stuff:
- Page titles (HTML title attribute)
- Meta description
- On page H1 tag

I'd like to do this on the following pages:
- home page
- category page
- brand page
- product page

I looked through a number of search results here related to SEO and most are pretty old so I think they may not be applicable to the newer template? I don't see anything relating to the title in most of the files in /html/ directory with the exception of the header.php

Where should I be looking in order to be able to adjust these?

I also noticed that some pages that no longer exist (for example, brand that was merged) still give a 200 response code. I'd like to fix this so old pages (old categories, products, brands, etc) respond with a 404 so they will be deindexed and not have the search engines seeing a number of empty / thin pages.

Do you have a suggestion on the best way to accomplish this?

Thanks!

Submitted by support on Wed, 2018-02-14 09:55

Hi,

As with the other HTML modules, html/header.php supports the input variables $header["title"] and $header["meta"] where the latter is an associative array of name and content key pairs, for example "description" and "keywords". To see how this works, check the example blank content page example.php in the distribution, where you will see the following code beginning at line 4:

  $header["title"] = "Example Page";
  $header["meta"]["description"] = "Example page meta description";
  $header["meta"]["keywords"] = "Example, Page, Meta, Keywords";

With regards to H1 tags, these can be included directly within the HTML modules where required, for example, for the product page, the main product name is output within H1 tags at line 54:

    <h1><?php print $product_main["name"]; ?></h1>

Further regarding the product page, meta description and keywords are set in the corresponding top level script products.php starting at line 70:

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

The home page (index.php) doesn't set a $header["title"] variable since html/header.php uses $config_siteTitle (config.php line 2) if $header["title"] is not set.

To add meta description and keywords to your home page, edit index.php and look for the following code at line 4:

  require("html/header.php");

...and REPLACE with:

  $header["meta"]["description"] = "Home page meta description";
  $header["meta"]["keywords"] = "Home, Page, Meta, Keywords";
  require("html/header.php");

Merchant, category and brand index search results are generated by search.php which by default uses a title corresponding to the query (e.g. merchant:Merchant Name:) at line 15:

    $header["title"] = $q;

Now, if you wanted to add meta tags for the search engine friendly merchant / category and brand pages (assuming $config_useRewrite is set to TRUE in config.php at line 8) this can be identified by the $rewrite variable. At the above point in search.php, the index name is in $parts[0] and the value in $parts[1], so to create separate description and keyword meta tags for each case, you could use something like:

    if ($rewrite)
    {
      switch($parts[0])
      {
        case "merchant":
          $header["title"] = $parts[1];
          $header["meta"]["description"] = "Merchant search results for ".$parts[1];
          $header["meta"]["keywords"] = "merchant,keywords,for,".$parts[1];
          break;
        case "category":
          $header["title"] = $parts[1];
          $header["meta"]["description"] = "Category search results for ".$parts[1];
          $header["meta"]["keywords"] = "category,keywords,for,".$parts[1];
          break;
        case "brand":
          $header["title"] = $parts[1];
          $header["meta"]["description"] = "Brand search results for ".$parts[1];
          $header["meta"]["keywords"] = "brand,keywords,for,".$parts[1];
          break;
      }
    }

Bear in mind that the above would display on every page which could lead to duplicate meta content issues. This is resolved for the title by the addition of the page number at line 547 (after adding the above code)

    if ($page > 1)
    {
      $header["title"] .= " | ".translate("Page")." ".$page;
    }

So to do the same for the meta tags, REPLACE with:

    if ($page > 1)
    {
      $header["title"] .= " | ".translate("Page")." ".$page;
      if (isset($header["meta"]["description"])) $header["meta"]["description"] .= " | ".translate("Page")." ".$page;
      if (isset($header["meta"]["keywords"])) $header["meta"]["keywords"] .= " | ".translate("Page")." ".$page;
    }

Finally, to add an H1 version of the title for merchant / category / brand pages, $rewrite can be used again at the top of html/searchresults.php, for example:

<?php if ($rewrite): ?>
  <div class='row'>
    <div class='small-12 columns'>
      <h1><?php print $header["title"]; ?></h1>
    </div>
  </div>
<?php endif; ?>

Cheers,
David.
--
PriceTapestry.com

Submitted by mlepisto on Wed, 2018-02-14 21:22

Thanks very much for the comprehensive explanation David. I was looking in /html/ for those files initially, I didn't realize it was in the root.

What do you suggest for where to catch the empty page that is giving a 200 vs a 404 so I can tell it to send the correct header?

Submitted by support on Thu, 2018-02-15 08:20

Ah apologies for missing that - to 404 old index search results pages, edit search.php and look for the following code at line 534:

  require("html/header.php");

...and REPLACE with:

  if ($rewrite && !isset($searchresults))
  {
    header("HTTP/1.0 404 Not Found");
    exit();
  }
  require("html/header.php");

Cheers,
David.
--
PriceTapestry.com

Submitted by mlepisto on Thu, 2018-02-15 21:11

Thanks David, unfortunately that is producing a 500 error. I don't have details as to what is in that error (that's another issue I need to look into as display_errors is set to ON)

I'm guessing the headers are being sent first somewhere and this is causing a conflict.

Here's what worked though (just a slight modification to your code) since it sets the response code to be sent with the headers. I also elected to not exit, that way it can render the page and provide users with alternate links (and I can also customize the 404 display further)

  if ($rewrite && !isset($searchresults))
  {
    http_response_code(404);
  }

In case anyone else is looking to do this too, I also added the following to products.php at line 154, so now any missing product pages will also provide a 404 to help clean up any empty cached pages in search engines.

  if ($rewrite && !isset($product))
  {
    http_response_code(404);
  }