PrestaShop Forum

The best place in the world to ask questions about PrestaShop and get advice from our passionate community!

PrestaShop Forum

Jump to content

 

[How-To] Prevent Meta Tag Duplication

93 replies to this topic
#1
tomerg3

    PrestaShop Superstar

  • US Moderators
  • 5750 posts
The "Sort Order" and "Pagination" create new URLs for pages, with different content in them, but using the same Page Title and description.

URL/11-category-name
URL/11-category-name?orderby=name&orderway=asc
URL/11-category-name?orderby=name&orderway=desc
URL/11-category-name?orderby=price&orderway=asc
URL/11-category-name?orderby=price&orderway=desc
URL/11-category-name?orderby=quantity&orderway=desc

Search Engines see this as duplicate meta tag information, and may penalize you for it.

You can change that by adding the sort order and page number into the Meta Tag information, which will make each page unique.


Open /classes/Tools.php and replace the function completeMetaTags (around line #500) with the function below.


static public function completeMetaTags($metaTags, $defaultValue)
{
global $cookie;
$no_duplication = "";
if (self::getValue('orderby'))
$no_duplication .= self::getValue('orderby')." ".self::getValue('orderway');
if (self::getValue('p'))
$no_duplication .= ($no_duplication != ""?" #":"#").self::getValue('p');
if (self::getValue('n'))
$no_duplication .= ($no_duplication != ""?" ":"").self::getValue('n');
if ($no_duplication != "")
$no_duplication = " (".$no_duplication.")";
if ($metaTags['meta_title'] == NULL)
$metaTags['meta_title'] = Configuration::get('PS_SHOP_NAME').' - '.$defaultValue;
$metaTags['meta_title'] .= $no_duplication;
if ($metaTags['meta_description'] == NULL)
$metaTags['meta_description'] = (Configuration::get('PS_META_DESCRIPTION', intval($cookie->id_lang)) ? Configuration::get('PS_META_DESCRIPTION', intval($cookie->id_lang)) : '');
$metaTags['meta_description'] .= $no_duplication;
if ($metaTags['meta_keywords'] == NULL)
$metaTags['meta_keywords'] = Configuration::get('PS_META_KEYWORDS', intval($cookie->id_lang)) ? Configuration::get('PS_META_KEYWORDS', intval($cookie->id_lang)) : '';
return $metaTags;
}


Open /classes/Tools.php and replace the function getHomeMetaTags (around line #490) with the function below.



static public function getHomeMetaTags($id_lang)
{
global $cookie, $page_name;

/* Metas-tags */
$metas = Meta::getMetaByPage($page_name, $id_lang);
$ret['meta_title'] = (isset($metas['title']) AND $metas['title']) ? Configuration::get('PS_SHOP_NAME').' - '.$metas['title'] : Configuration::get('PS_SHOP_NAME');
$ret['meta_description'] = (isset($metas['description']) AND $metas['description']) ? $metas['description'] : '';
$ret['meta_keywords'] = (isset($metas['keywords']) AND $metas['keywords']) ? $metas['keywords'] : '';
$no_duplication = "";
if (self::getValue('orderby'))
$no_duplication .= self::getValue('orderby')." ".self::getValue('orderway');
if (self::getValue('p'))
$no_duplication .= ($no_duplication != ""?" #":"#").self::getValue('p');
if (self::getValue('n'))
$no_duplication .= ($no_duplication != ""?" ":"").self::getValue('n');
if ($no_duplication != "")
{
$ret['meta_title'] .= " (".$no_duplication.")";
$ret['meta_description'] .= " (".$no_duplication.")";
}
return $ret;
}


For more SEO tips check out http://www.presto-ch...estashopseotips
Posted Image
For the latest updates discount coupons and new module information follow us on Twitter , Facebook ,and tips on our Blog
Please do not send general questions via PM, that is what the forum is for...

#2
whitelighter

    PrestaShop Addict

  • Members
  • PipPipPip
  • 589 posts
Actually you can use Google webmaster tools to have Google ignore the parameters orderway and orderby, then they will all appear as the same page. This way you won't have to compromise the integrity of core files.

#3
tomerg3

    PrestaShop Superstar

  • US Moderators
  • 5750 posts

From 1272222144:

Actually you can use Google webmaster tools to have Google ignore the parameters orderway and orderby, then they will all appear as the same page. This way you won't have to compromise the integrity of core files.


This is a much safer way, and will also affect other search engines that do not offer that option.
Posted Image
For the latest updates discount coupons and new module information follow us on Twitter , Facebook ,and tips on our Blog
Please do not send general questions via PM, that is what the forum is for...

#4
whitelighter

    PrestaShop Addict

  • Members
  • PipPipPip
  • 589 posts

From 1272222454:

From 1272222144:

Actually you can use Google webmaster tools to have Google ignore the parameters orderway and orderby, then they will all appear as the same page. This way you won't have to compromise the integrity of core files.


This is a much safer way, and will also affect other search engines that do not offer that option.


We will have to agree to disagree on this. This method adds words to the meta tags that you normally may not want, reduces the focus on the actual descriptive text etc.
You can also use robots.txt to block crawling of these pages with unwanted parameters. But that is slightly risky and requires careful examination before implementing.

#5
tomerg3

    PrestaShop Superstar

  • US Moderators
  • 5750 posts
I have just updated this code (In the first post) to display the additional text for the description better (it was not showing is some cases).

I use a similar technique on TennisLessons.com, the site is ranked in the top 5 for tennis lessons + any city and it gets over 20,000 visitors a month from natural search engine results.
Posted Image
For the latest updates discount coupons and new module information follow us on Twitter , Facebook ,and tips on our Blog
Please do not send general questions via PM, that is what the forum is for...

#6
Guest__*
  • Guests
Hi, is this problem solved in the lasted version 1.3.0.6? Do we still need to modify the code manually?

#7
Timpet

    PrestaShop Fanatic

  • Members
  • PipPipPipPip
  • 1042 posts
This is'nt a bad ay to do it.

Only if you use the categories as landingpages (i do) could'nt it ceate keyword canibalisem? I will now be having 4+ pages that uses the same keyword's wouldnt the best way to use robots.txt to exclude the sites? Offcouse this would exclude some products from being indexed?
Webpack 2 - Postdanmark pakkelabels direkte fra Back Office | Prestashop blog på dansk
Meebox rabatkode der giver 20% rabat: prestatips.dk

#8
tomerg3

    PrestaShop Superstar

  • US Moderators
  • 5750 posts
Just updated the code in the first post to include additional pages (new products, best sellers, etc...)
Posted Image
For the latest updates discount coupons and new module information follow us on Twitter , Facebook ,and tips on our Blog
Please do not send general questions via PM, that is what the forum is for...

#9
gleb

    PrestaShop Newbie

  • Members
  • Pip
  • 14 posts
This is a nice way to deal with this problem. I'm not much of a coder so I can not understand exactly what is being changed. Is there any visible changes so I will know if the code works or not. ie in the url or with tools

#10
David @ gfe.

    PrestaShop Apprentice

  • Members
  • PipPip
  • 367 posts
Tomerg,
Have ben slowly going through the changes made by adding your code to the tools.php, installing your 301 mod and edited the htaccess.

I notice that i now get two urls which point to the same page. Neither is redirecting so am i right in saying that i still have duplicate urls? That is how Google seems to be reading them.

They read:

n=10&orderby=position&orderway=desc&p=3
and,
n=10&orderby=position&orderway=desc&p=3&id_category=27

As I say, both land on the same page but the URL remain different in the address bar. I am assuming the first url here is the one that your suggestions/tools.php edits/module, etc have created, yes?
Games from Everywhere

Best Board Games | Wooden Chess Sets

#11
Celou

    PrestaShop Apprentice

  • Members
  • PipPip
  • 33 posts

From 1273326850:

Just updated the code in the first post to include additional pages (new products, best sellers, etc...)


Hi Tomer,

With new-products.php it does not work.
Why?

Thank you in advance for the answer.

#12
tomerg3

    PrestaShop Superstar

  • US Moderators
  • 5750 posts
Did you also change getHomeMetaTags?

That takes care of the new-product / best-seller etc... pages.
Posted Image
For the latest updates discount coupons and new module information follow us on Twitter , Facebook ,and tips on our Blog
Please do not send general questions via PM, that is what the forum is for...

#13
Celou

    PrestaShop Apprentice

  • Members
  • PipPip
  • 33 posts
Hi Tomer,

Now it's all OK

But in page http://www.presto-ch...estashopseotips


you write "(unless manually changed)" : it was my case and i'd not change. Now I've change and it's all right.

Thank you very much!!!

Marcel.

#14
Timpet

    PrestaShop Fanatic

  • Members
  • PipPipPipPip
  • 1042 posts
This have done wounders for my page, along with his Duplicate URL Redirect v1.1.9 payed module!! Go fore it guys!
Webpack 2 - Postdanmark pakkelabels direkte fra Back Office | Prestashop blog på dansk
Meebox rabatkode der giver 20% rabat: prestatips.dk

#15
Timpet

    PrestaShop Fanatic

  • Members
  • PipPipPipPip
  • 1042 posts
Im using these changes, but have these problemes:

Kvalitets bluser, som samtidigt er billige bluser. Bluser til mange formål. (name asc #5)
/shop/10-bluser?side=10&;varekat=&;p=5&orderby=name&orderway=asc&p=5

/shop/10-bluser?side=2&;varekat=1-2-3&;p=5&orderby=name&orderway=asc&p=5

/shop/10-bluser?side=6&;varekat=&orderby=name&orderway=asc&p=5

/shop/10-bluser?varekat=2&;p=4&orderby=name&orderway=asc&p=5

What am i missing?
Webpack 2 - Postdanmark pakkelabels direkte fra Back Office | Prestashop blog på dansk
Meebox rabatkode der giver 20% rabat: prestatips.dk

#16
tomerg3

    PrestaShop Superstar

  • US Moderators
  • 5750 posts
you seem to have other variables in the category page ("side" and "varekat"), you can add their values to the meta tags so they will be unique.

if (self::getValue('side'))
$no_duplication .= ($no_duplication != ""?" ":"").self::getValue('side');

Posted Image
For the latest updates discount coupons and new module information follow us on Twitter , Facebook ,and tips on our Blog
Please do not send general questions via PM, that is what the forum is for...

#17
outlet.ee

    PrestaShop Apprentice

  • Members
  • PipPip
  • 175 posts
Works perfectly, thank you!

I do not see the lang parameters in the code, how could I change the text to appropriate language (price asc 30)?

#18
Timpet

    PrestaShop Fanatic

  • Members
  • PipPipPipPip
  • 1042 posts
I found a minor "bug" in this (wich btw is great!)

When changing sort, product page, number of products shown the URL is not completly the same all the way.

A short exampel:
pressed in order sort -> page -> numbers returns the URL:
4-sexet-toj?n=10&orderby=price&orderway=asc&p=2

Now i press sort to something else and returns to price and asc and this gives the URL:
4-sexet-toj?n=10&p=2&orderby=price&orderway=asc

Notice how the p=2 has moved.

These to URL's has the same content, and same meta title and decription useing these changes. Therefor i took matters in my own hands and made some changes to tomer3 code.
static public function completeMetaTags($metaTags, $defaultValue)
{
global $cookie;
$no_duplication = "";
$input_url = $_SERVER['REQUEST_URI'];
$all_vars = explode("?", $input_url);
$spec_vars = explode("&", $all_vars[1]);
$loop = 0;
//$no_duplication .= print_r($all_vars);
while($spec_vars[$loop]) {
$type_and_var = explode("=", $spec_vars[$loop]);
if (($type_and_var[0] == 'p') || ($type_and_var[0] == 'orderby') || ($type_and_var[0] == 'orderway') || ($type_and_var[0] == 'n')) {
if ($type_and_var[0] == 'p') { $no_duplication .= '#'.$type_and_var[1].' '; }
else { $no_duplication .= $type_and_var[1].' '; }
}
$loop++;
}
if ($no_duplication != "")
$no_duplication = " ( ".$no_duplication.")";
if ($metaTags['meta_title'] == NULL)
$metaTags['meta_title'] = Configuration::get('PS_SHOP_NAME').' - '.$defaultValue;
$metaTags['meta_title'] .= $no_duplication;
if ($metaTags['meta_description'] == NULL)
$metaTags['meta_description'] = (Configuration::get('PS_META_DESCRIPTION', intval($cookie->id_lang)) ? Configuration::get('PS_META_DESCRIPTION', intval($cookie->id_lang)) : '');
$metaTags['meta_description'] .= $no_duplication;
if ($metaTags['meta_keywords'] == NULL)
$metaTags['meta_keywords'] = Configuration::get('PS_META_KEYWORDS', intval($cookie->id_lang)) ? Configuration::get('PS_META_KEYWORDS', intval($cookie->id_lang)) : '';
return $metaTags;
}


And

static public function getHomeMetaTags($id_lang)
{
global $cookie, $page_name;

/* Metas-tags */
$metas = Meta::getMetaByPage($page_name, $id_lang);
$ret['meta_title'] = (isset($metas['title']) AND $metas['title']) ? Configuration::get('PS_SHOP_NAME').' - '.$metas['title'] : Configuration::get('PS_SHOP_NAME');
$ret['meta_description'] = (isset($metas['description']) AND $metas['description']) ? $metas['description'] : '';
$ret['meta_keywords'] = (isset($metas['keywords']) AND $metas['keywords']) ? $metas['keywords'] : '';
$no_duplication = "";
$input_url = $_SERVER['REQUEST_URI'];
$all_vars = explode("?", $input_url);
$spec_vars = explode("&", $all_vars[1]);
$loop = 0;
//$no_duplication .= print_r($all_vars);
while($spec_vars[$loop]) {
$type_and_var = explode("=", $spec_vars[$loop]);
if (($type_and_var[0] == 'p') || ($type_and_var[0] == 'orderby') || ($type_and_var[0] == 'orderway') || ($type_and_var[0] == 'n')) {
if ($type_and_var[0] == 'p') { $no_duplication .= '#'.$type_and_var[1].' '; }
else { $no_duplication .= $type_and_var[1].' '; }
}
$loop++;
}
if ($no_duplication != "")
{
$ret['meta_title'] .= " ( ".$no_duplication.")";
$ret['meta_description'] .= " ( ".$no_duplication.")";
}
return $ret;
}


All the credit should go to tomer3 for the inspiration for this change.

the number pr page does allso add id_category to the URL, wich kinda sucks to those how use rewrite, because this is allready in the URL. But i havent found the solution for this issue yet, but am working on it :)
Webpack 2 - Postdanmark pakkelabels direkte fra Back Office | Prestashop blog på dansk
Meebox rabatkode der giver 20% rabat: prestatips.dk

#19
henrycr

    PrestaShop Apprentice

  • Members
  • PipPip
  • 245 posts
I have version 1.1.5 or in addition to friendly urls enabled

in google webmaster says I have a problem of meta tag dupliacacion

I can use this modification?

#20
salgcsm

    PrestaShop Newbie

  • Members
  • Pip
  • 2 posts
Hi all Presta SEO users

I read all the posts - but I still can't get Google to "act"...

My issues is:

We got this website http://www.cs-m.dk which we really try to improve on Google results.
But GWT keeps telling me that there are errors. Duplicate contents - and I now THIS punish the website hard...

SO:

1. The first error is trouble with the "duplicate meta descriptions" and
"Duplicate content orderby=name&orderway=asc" - and so on. Please see screendump 1.

2. The second error is that i get errors i GWT on the "Short meta descriptions". Please see screendump 2.

3. The third error is "Duplicate title tags" - Please see screendump 3.

4. My last problem is "Crawl errors" - see nr. 4 + 5

PLEASE HELP - how do I correct these errors. I have copied the new code posted in here to: /classes/tools.php - NO LUCK..!

Attached Files

  • Attached File  1.png   90bytes   1008 downloads
  • Attached File  2.png   108bytes   948 downloads
  • Attached File  3.png   76bytes   903 downloads
  • Attached File  4.png   131bytes   902 downloads
  • Attached File  5.png   29bytes   885 downloads