Jump to content

[Free module] Prestashop canonical, hreflang, next, prev, noindex tags


Daresh
 Share

Recommended Posts

Duplicate content is something that search engine robots don't like.

To avoid it, it's recommended to add canonical links in the header of your shop.

It's also good to:

  • direct robots to other language versions of your shop with hreflang links
  • help them navigate through paginated content with prev and next links
  • prevent them from indexing unnecessary parts of the shop with noindex tag

To achieve all this, we combined some of the common solutions into one handy free module.

You can download the module directly here:

 

gmseofields.zip

or from this location

(module is for prestashop version 1.6, newer version has canonical tags already partially implemented, so maybe other are coming soon)

Edited by Daresh (see edit history)
  • Like 5
  • Thanks 2

Share this post


Link to post
Share on other sites

Hi Daresh

Excellent module and working prefect.

But a suggestion hreflang should contain language code instead of iso code. example:-  

hreflang="en-gb"
hreflang="en-us"

As per google:  Make sure that all language codes you use identify the language (in ISO 639-1 format) and optionally the region (in ISO 3166-1 Alpha 2 format) of an alternate URL. Specifying the region alone is not valid.

Screenshot attached for your reference. 

 

Hope you will make an improvement.

Thanks

Improvement.png

Share this post


Link to post
Share on other sites

  • 2 weeks later...

Thanks for the feedback, I just updated the module to have the language code instead of the iso code, so please test.

I don't know if setting hreflang for sites having one language is proper, but if you have any information about it just let me know and I'll be happy to update the module :)

Share this post


Link to post
Share on other sites

;) I am not sure about it. I try to gain this information reading articles about SEO. But still I am not sure if it is correct. But for instance: 

<link rel="prev" href="https://www.example.com/category-29">
<link rel="next" href="https://www.example.com/category-29?p=3">
<link rel="canonical" href="https://www.example.com/category-29">
<link rel="alternate" href="https://www.example.com/category-29?p=2" hreflang="pl">
<link rel="alternate" href="https://www.example.com/category-29?p=2" hreflang="x-default">

Then, we have the following situation: Because of the fact  that main and the only one languge is "pl".
we have on the page two self-referencing links. I'm still confused about that. 
From one point of view, it is still valuable information for Google (meta), but possibly overflowed.

 

 

Share this post


Link to post
Share on other sites

Hreflang is not required for single language site. Hreflang tells google that the site is available in multiple language and to be shown in particular geo location depending upon language.

Thanks for the module update.

 

 

Share this post


Link to post
Share on other sites

  • 2 months later...

Hello,

I am currently working on the code to implement in my site prestashop but I am in version 1.7

I'm having a problem with foreach loops.
I used as a base code for a version 1.6

 

{if $page_name == 'category'}
    {foreach $languages as $lang}
        {if $lang_iso != $lang.iso_code}
        <link rel="alternate" hreflang="{$lang.language_code}" href="{$link->getCategoryLink($smarty.get.id_category, null, $lang.id_lang,null,null )}/" />
        {/if}
    {/foreach}
{/if}
 
{if $page_name == 'product'}
    {foreach $languages as $lang}
        {if $lang_iso != $lang.iso_code}
        <link rel="alternate" hreflang="{$lang.language_code}" href="{$link->getProductLink($smarty.get.id_product, null, null, null, $lang.id_lang, null, 0, false)}/" />
        {/if}
    {/foreach}
{/if}
 
{if $page_name == 'cms'}
    {foreach $languages as $lang}
        {if $lang_iso != $lang.iso_code}
        <link rel="alternate" hreflang="{$lang.language_code}" href="{$link->getCMSLink($smarty.get.id_cms, null, false, $lang.id_lang)}/" />
        {/if}
    {/foreach}
{/if}
 
{if $page_name == 'manufacturer'}
    {foreach $languages as $lang}
        {if $lang_iso != $lang.iso_code}
        <link rel="alternate" hreflang="{$lang.language_code}" href="{$link->getManufacturerLink($smarty.get.id_manufacturer, null, $lang.id_lang , null)}/" />
        {/if}
    {/foreach}
{/if}
 
{if $page_name == 'index'}
    {foreach $languages as $lang}
        {if $lang_iso != $lang.iso_code}
        <link rel="alternate" hreflang="{$lang.language_code}" href="/{$lang.iso_code}/"/>
        {/if}
    {/foreach}
{/if}
 
for the index page I did this because I could not make the code work
 
{if $page.page_name == 'index'}
        <link rel="alternate" hreflang="fr" href="https://mysite.com/fr/"/>
        <link rel="alternate" hreflang="de" href="https://mysite.com/de/"/>
        <link rel="alternate" hreflang="en" href="https://mysite.com/en/"/>
        <link rel="alternate" hreflang="es" href="https://mysite.com/es/"/>
        <link rel="alternate" hreflang="it" href="https://mysite.com/it/"/>
        <link rel="alternate" hreflang="nl" href="https://mysite.com/nl/"/>
        <link rel="alternate" hreflang="pl" href="https://mysite.com/pl/"/>
        <link rel="alternate" hreflang="pt" href="https://mysite.com/pt/"/>
        <link rel="alternate" hreflang="ro" href="https://mysite.com/ro/"/>
{/if}

 
 

I am lost so if you have an idea or the variables to use in the foreach to be able to integrate the hreflang tag in other pages it would be the best.

PS: last information my site is in SSL

Edited by montana063 (see edit history)

Share this post


Link to post
Share on other sites

  • 3 weeks later...
On 2/14/2018 at 5:28 PM, Daresh said:

gmseofields.zipDuplicate content is something that search engine robots don't like.

To avoid it, it's recommended to add canonical links in the header of your shop.

It's also good to:

  • direct robots to other language versions of your shop with hreflang links
  • help them navigate through paginated content with prev and next links
  • prevent them from indexing unnecessary parts of the shop with noindex tag

To achieve all this, we combined some of the common solutions into one handy free module.

You can download the module directly here:

gmseofields.zip

(module is for prestashop version 1.6, newer version has canonical tags already partially implemented, so maybe other are coming soon)

Hi, please attach some image with what make your module. Thanks a lot!

Share this post


Link to post
Share on other sites

  • 4 weeks later...
  • 5 weeks later...

Hello! :) Thank you for your module and for your time. Really appreciate it.

I noticed that module generate hreflangs with country targeting. (EN-GB, CS-CZ etc.). I really like to have just the languange here, without any further specification. Can you please point me to the right direction? I can modify it myself, but cant find what should :)

 

Thank you!

Share this post


Link to post
Share on other sites

I thought about that, but i was afraid that this can disrupt my translations. I will backup my shop and try that, but i would be happier with just an "get iso" code. Im trying to understand the PHP file :)

 

Again, thank you for your time! :)

Share this post


Link to post
Share on other sites

  • 3 weeks later...

This module gave noindex, nofollow to all categories of the website! Please advise how to go around this issue. I've deleted module after I've seen this, but there is still meta noindex, nofollow across pages. 

Share this post


Link to post
Share on other sites

  • 1 month later...

Hello,

Thank you for the module, it is exactly what I needed.

However, for me (I am a novice...) it doesn't work properly. I use it in Prestashop 1.6.1.3

Here is the problem: I tested it with Flang,


     https://www.my_domain.com             Reciprocal not found
2.     https://www.my_domain.com/en     English         We can't found link on alternate location!
3.     https://www.my_domain.com/en     X-default         We can't found link on alternate location!
4.     https://www.my_domain.com/fr     French         We can't found link on alternate location!
5.     https://www.my_domain.com/es     Spanish; Castilian         We can't found link on alternate location!
6.     https://www.my_domain.com/de     German         We can't found link on alternate location!
7.     https://www.my_domain.com/it     Italian         We can't found link on alternate location!

 

I'll be very thankful if you could help me,

Thank you in advance,

Nina

Share this post


Link to post
Share on other sites

10 hours ago, Nina said:

Hello,

Thank you for the module, it is exactly what I needed.

However, for me (I am a novice...) it doesn't work properly. I use it in Prestashop 1.6.1.3

Here is the problem: I tested it with Flang,


     https://www.my_domain.com             Reciprocal not found
2.     https://www.my_domain.com/en     English         We can't found link on alternate location!
3.     https://www.my_domain.com/en     X-default         We can't found link on alternate location!
4.     https://www.my_domain.com/fr     French         We can't found link on alternate location!
5.     https://www.my_domain.com/es     Spanish; Castilian         We can't found link on alternate location!
6.     https://www.my_domain.com/de     German         We can't found link on alternate location!
7.     https://www.my_domain.com/it     Italian         We can't found link on alternate location!

 

I'll be very thankful if you could help me,

Thank you in advance,

Nina

 

Hard to help without seeing the actual site..

 

52 minutes ago, Jason Wong said:

It appears the link for gmseofields.zip is broken.  If anyone has this module, please share it here.  Thank you.

 

Just downloaded it, works fine for me, another download location: http://greenmousestudio.com/en/seo-tags

Share this post


Link to post
Share on other sites

Just now, Nina said:

Hello,

Thank you for the module, it is exactly what I needed.

However, for me (I am a novice...) it doesn't work properly. I use it in Prestashop 1.6.1.3

Here is the problem: I tested it with Flang,


     https://www.my_domain.com             Reciprocal not found
2.     https://www.my_domain.com/en     English         We can't found link on alternate location!
3.     https://www.my_domain.com/en     X-default         We can't found link on alternate location!
4.     https://www.my_domain.com/fr     French         We can't found link on alternate location!
5.     https://www.my_domain.com/es     Spanish; Castilian         We can't found link on alternate location!
6.     https://www.my_domain.com/de     German         We can't found link on alternate location!
7.     https://www.my_domain.com/it     Italian         We can't found link on alternate location!

 

I'll be very thankful if you could help me,

Thank you in advance,

Nina

 

Share this post


Link to post
Share on other sites

Many thanks, Daresh. :)

It's working great for PS 1.6.1.6.

However, I noticed both hreflang and canonical tags are placed far at the bottom of the head section.

How do I get them to be placed on the top, say, after meta keywords?

 

Please advise.  Thank you.

Edited by Jason Wong (see edit history)

Share this post


Link to post
Share on other sites

  • 1 month later...
On 10/9/2018 at 4:11 AM, Jason Wong said:

Many thanks, Daresh. :)

It's working great for PS 1.6.1.6.

However, I noticed both hreflang and canonical tags are placed far at the bottom of the head section.

How do I get them to be placed on the top, say, after meta keywords?

 

Please advise.  Thank you.

You'll need to add a new hook in the <head> section, and modify the module to use this new hook instead, because as it is developed, it is using the default "displayHeader" hook

image.thumb.png.868cd575de212e692797dd92f51d7bf7.png

Share this post


Link to post
Share on other sites

Hi,

Sorry about the question. I installed the module on presta 1.6.1.23 and the installation is ok, the question is any configuration is needed? When I select configuration just a welcome message and donate filed is showed. I'm doing something wrong?

Thank you

Share this post


Link to post
Share on other sites

  • 1 month later...

hello, I want to omit the (rel part prev and rel next ) and edited the file gmseofields.php tell me please if I did it right

 

<?php
/**
 * Adds canonical, hreflang and prev next tags to the header
 *
 * @package   gmseofields
 * @author    Dariusz Tryba ([email protected]), based on Faktiva and ThirtyBees
 * @copyright Copyright (c) Green Mouse Studio (http://www.greenmousestudio.com)
 * @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
if (!defined('_PS_VERSION_')) exit;

class GmSeoFields extends Module
{
    private $nobotsControllers = array(
        '404',
        'address',
        'addresses',
        'attachment',
        'authentication',
        'cart',
        'discount',
        'footer',
        'get-file',
        'guest-tracking',
        'header',
        'history',
        'identity',
        'images.inc',
        'init',
        'my-account',
        'order',
        'order-opc',
        'order-slip',
        'order-detail',
        'order-follow',
        'order-return',
        'order-confirmation',
        'pagination',
        'password',
        'pdf-invoice',
        'pdf-order-return',
        'pdf-order-slip',
        'product-sort',
        'search',
        'statistics',
    );

    public function __construct()
    {
        $this->name = 'gmseofields';
        $this->tab = 'front_office_features';
        $this->version = '1.0.2';
        $this->author = 'GreenMouseStudio.com';
        $this->bootstrap = true;
        $this->need_instance = 0;

        parent::__construct();

        $this->displayName = $this->l('SEO Fields');
        $this->description = $this->l('Adds canonical, hreflang, prev, next and noindex tags to the header');
        $this->ps_versions_compliancy = array('min' => '1.6', 'max' => '1.6.99.99');
    }

    public function install()
    {
        return parent::install() && $this->registerHook('displayHeader');
    }

    public function getContent()
    {
        return $this->context->smarty->fetch($this->local_path.'views/templates/admin/gms.tpl');
    }

    public function hookDisplayHeader()
    {
        if ($this->handleNobots()) {
            // no need to add anything else as robots should ignore this page
            return;
        }
        //Nothing more neaded for ThirtyBees
        if (defined('_TB_VERSION_')) {
            return;
        }

        if (isset($this->context->controller->php_self)) {
            $this->php_self = $this->context->controller->php_self;
            return $this->getSeoFields();
        }
    }

    private function handleNobots()
    {
        if (in_array($this->context->controller->php_self, $this->nobotsControllers, true) || Tools::getValue('selected_filters')
        ) {
            $this->context->smarty->assign('nobots', true);
            return true;
        }
        return false;
    }

    public function getSeoFields()
    {
        $content = '';
        $languages = Language::getLanguages();
        $defaultLang = Configuration::get('PS_LANG_DEFAULT');
        switch ($this->php_self) {
            case 'product': // product page
                $idProduct = (int) Tools::getValue('id_product');
                $canonical = $this->context->link->getProductLink($idProduct);
                $hreflang = $this->getHrefLang('product', $idProduct, $languages, $defaultLang);

                break;

            case 'category':
                $idCategory = (int) Tools::getValue('id_category');
                $canonical = $this->context->link->getCategoryLink((int) $idCategory);
                $hreflang = $this->getHrefLang('category', $idCategory, $languages, $defaultLang);

                break;

            case 'manufacturer':
                $idManufacturer = (int) Tools::getValue('id_manufacturer');
                $hreflang = $this->getHrefLang('manufacturer', $idManufacturer, $languages, $defaultLang);

                if (!$idManufacturer) {
                    $canonical = $this->context->link->getPageLink('manufacturer');
                } else {
                    $canonical = $this->context->link->getManufacturerLink($idManufacturer);
                }

                break;

            case 'supplier':
                $idSupplier = (int) Tools::getValue('id_supplier');
                $hreflang = $this->getHrefLang('supplier', $idSupplier, $languages, $defaultLang);

                if (!Tools::getValue('id_supplier')) {
                    $canonical = $this->context->link->getPageLink('supplier');
                } else {
                    $canonical = $this->context->link->getSupplierLink((int) Tools::getValue('id_supplier'));
                }

                break;

            case 'cms':
                $idCms = Tools::getValue('id_cms');
                $idCmsCategory = Tools::getValue('id_cms_category');
                if ($idCms) {
                    $canonical = $this->context->link->getCMSLink((int) $idCms);
                    $hreflang = $this->getHrefLang('cms', (int) $idCms, $languages, $defaultLang);
                } else {
                    $canonical = $this->context->link->getCMSCategoryLink((int) $idCmsCategory);
                    $hreflang = $this->getHrefLang('cms_category', (int) $idCmsCategory, $languages, $defaultLang);
                }
                break;

            default:
                $canonical = $this->context->link->getPageLink($this->php_self);
                $hreflang = $this->getHrefLang($this->php_self, 0, $languages, $defaultLang);
                break;
        }
        // build new content
        $content .= '<link rel="canonical" href="'.$canonical.'">'."\n";
        if (is_array($hreflang) && !empty($hreflang)) {
            foreach ($hreflang as $lang) {
                $content .= "$lang\n";
            }
        }

        return $content;
    }

    public function getHrefLang($entity, $idItem, $languages, $idLangDefault)
    {
        $links = array();
        foreach ($languages as $lang) {
            switch ($entity) {
                case 'product':
                    $lnk = $this->context->link->getProductLink((int) $idItem, null, null, null, $lang['id_lang']);
                    break;

                case 'category':
                    $lnk = $this->context->link->getCategoryLink((int) $idItem, null, $lang['id_lang']);
                    break;
                case 'manufacturer':
                    if (!$idItem) {
                        $lnk = $this->context->link->getPageLink('manufacturer', null, $lang['id_lang']);
                    } else {
                        $lnk = $this->context->link->getManufacturerLink((int) $idItem, null, $lang['id_lang']);
                    }
                    break;
                case 'supplier':
                    if (!$idItem) {
                        $lnk = $this->context->link->getPageLink('supplier', null, $lang['id_lang']);
                    } else {
                        $lnk = $this->context->link->getSupplierLink((int) $idItem, null, $lang['id_lang']);
                    }
                    break;
                case 'cms':
                    $lnk = $this->context->link->getCMSLink((int) $idItem, null, null, $lang['id_lang']);
                    break;
                case 'cms_category':
                    $lnk = $this->context->link->getCMSCategoryLink((int) $idItem, null, $lang['id_lang']);
                    break;
                default:
                    $lnk = $this->context->link->getPageLink($entity, null, $lang['id_lang']);
                    break;
            }

            // append page number
            if ($p = Tools::getValue('p')) {
                $lnk .= "?p=$p";
            }

            $links[] = '<link rel="alternate" href="'.$lnk.'" hreflang="'.$lang['language_code'].'">';
            if ($lang['id_lang'] == $idLangDefault) {
                $links[] = '<link rel="alternate" href="'.$lnk.'" hreflang="x-default">';
            }
        }

        return $links;
    }

    public function getRelPrevNext($entity, $idItem)
    {
        switch ($entity) {
            case 'category':
                $category = new Category((int) $idItem);
                $nbProducts = $category->getProducts(null, null, null, null, null, true);
                break;
            case 'manufacturer':
                $manufacturer = new Manufacturer($idItem);
                $nbProducts = $manufacturer->getProducts($manufacturer->id, null, null, null, null, null, true);
                break;
            case 'supplier':
                $supplier = new Supplier($idItem);
                $nbProducts = $supplier->getProducts($supplier->id, null, null, null, null, null, true);
                break;
            default:
                return '';
        }

        $p = Tools::getValue('p');
        $n = (int) Configuration::get('PS_PRODUCTS_PER_PAGE');

        $totalPages = ceil($nbProducts / $n);

        $linkprev = '';
        $linknext = '';
        $requestPage = $this->context->link->getPaginationLink($entity, $idItem, $n, false, 1, false);
        if (!$p) {
            $p = 1;
        }

        if (Configuration::get('PS_REWRITING_SETTINGS')) {
            $requestPage = strtok($requestPage, '?');
        }

        if ($p > 1) { // we need prev
            $linkprev = $this->context->link->goPage($requestPage, $p - 1);
        }

        if ($totalPages > 1 && $p + 1 <= $totalPages) {
            $linknext = $this->context->link->goPage($requestPage, $p + 1);
        }

        $return = '';

        if ($linkprev) {
            $return .= '<link rel="prev" href="'.$linkprev.'">';
        }
        if ($linknext) {
            $return .= '<link rel="next" href="'.$linknext.'">';
        }
        return $return;
    }
}
 

Share this post


Link to post
Share on other sites

Hello, how can I modify the module so that the language tag changes its format, for example, currently in Spanish I have it so hreflang = "es-es"> but I want it to be like this hreflang = "es" I want to change it because it seems to google puts problem if the page label is not equal to hreflang I put this thread where you can see that many people have this problem https://productforums.google.com/forum/#!topic/webmaster-en/dmo8Oupju-0

Share this post


Link to post
Share on other sites

3 minutes ago, juanrojas said:

Hello, how can I modify the module so that the language tag changes its format, for example, currently in Spanish I have it so hreflang = "es-es"> but I want it to be like this hreflang = "es" I want to change it because it seems to google puts problem if the page label is not equal to hreflang I put this thread where you can see that many people have this problem https://productforums.google.com/forum/#!topic/webmaster-en/dmo8Oupju-0

Invalid link, or maybe not a public thread?

Share this post


Link to post
Share on other sites

On 2/14/2018 at 8:28 PM, Daresh said:

Duplicate content is something that search engine robots don't like.

To avoid it, it's recommended to add canonical links in the header of your shop.

It's also good to:

  • direct robots to other language versions of your shop with hreflang links
  • help them navigate through paginated content with prev and next links
  • prevent them from indexing unnecessary parts of the shop with noindex tag

To achieve all this, we combined some of the common solutions into one handy free module.

You can download the module directly here:

gmseofields.zip

or from this location

(module is for prestashop version 1.6, newer version has canonical tags already partially implemented, so maybe other are coming soon)

 

 

Edited by Bilal17
I have Prestashop 1.7.4 version. Which is best canonical tag module? (see edit history)

Share this post


Link to post
Share on other sites

  • 3 weeks later...
  • 1 month later...

I'm not a programmer, and I spent a lot of time solving the problem of canonical links. Everything was decided with this module. Thank you very much!

Edited by antoxa7 (see edit history)

Share this post


Link to post
Share on other sites

Hi, at first thank you very much for the module. I've installed today the module over prestashop 1.6.1.20 and works well. I see don't apply labels rel previous next in best seller and new products modules. Is this normal? Aren't implemented in this modules yet?

Thanks in advance. 

 

Share this post


Link to post
Share on other sites

Will be implemented the tag for the best seller and new products modules in the future or this isn't necessary for this modules?
By the way, my store is only in one language. How can I remove the hreflang tag?

Thanks again for your reply

Share this post


Link to post
Share on other sites

  • 2 weeks later...
On 2/14/2018 at 5:28 PM, Daresh said:

Duplicate content is something that search engine robots don't like.

To avoid it, it's recommended to add canonical links in the header of your shop.

It's also good to:

  • direct robots to other language versions of your shop with hreflang links
  • help them navigate through paginated content with prev and next links
  • prevent them from indexing unnecessary parts of the shop with noindex tag

To achieve all this, we combined some of the common solutions into one handy free module.

You can download the module directly here:

 

gmseofields.zip

or from this location

(module is for prestashop version 1.6, newer version has canonical tags already partially implemented, so maybe other are coming soon)

Hi, thanks for the great module! Almost everything works correctly for me except for the tag Prev and Next. The prev tag is not displayed at all on all pages and the next tag only indicates page 2, even if the current page is 3 or higher. Maybe someone can help me - Prestashop 1.6.1.23 & Transformer theme 3

Here is an example view-source:https://www.chemodanoff.com.ua/ru/15-чемоданы-hauptstadtkoffer#/page-3

Share this post


Link to post
Share on other sites

  • 2 weeks later...

Hello, I find the following and is that the attributes do not put the canonical url as it should for example this is the route of the url with its attribute

.../de/abdeckung-fuer-bebe-confort-rodifix-airprotect-gruppe-23.html#/12-gestempelt-racoon_town

but if I observe the canonical url it is the following

.../de/abdeckung-fuer-bebe-confort-rodifix-airprotect-gruppe-23.html

that is, it puts it without identifying the attribute.

the documentation says the following: Such a combination of elements can confuse search engines because it suggests different URLs for indexation. The best practice is to either remove the canonical tag or to link the canonical element to the page itself.

How can I solve it?

 

Share this post


Link to post
Share on other sites

  • 5 weeks later...

Hi, Daresh,

thanks for the great module!

Almost everything works correctly for me except for the tag Prev and Next. The prev tag is not displayed at all on all pages and the next tag only indicates page 2, even if the current page is 3 or higher.- Prestashop 1.6.1.16

Share this post


Link to post
Share on other sites

  • 1 month later...
  • 2 months later...
  • 2 weeks later...

Hello.
After analysis found: Errors found in the use of hreflang elements. Check the other sections in the Localization options group to find and fix them.
After viewing the details, it found 148 problems, the site shows not 3 but 5. The screen added

Скриншот 15-10-2019 12.29.32.jpg

Share this post


Link to post
Share on other sites

  • 1 month later...
  • 3 weeks later...
On 10/15/2019 at 11:32 AM, infozhashkiv said:

Hello.
After analysis found: Errors found in the use of hreflang elements. Check the other sections in the Localization options group to find and fix them.
After viewing the details, it found 148 problems, the site shows not 3 but 5. The screen added

Скриншот 15-10-2019 12.29.32.jpg

Hello,

 

Dit you manage to solve this hreflang issue ?

I have similar issues on my website : there is only French but it says there are no return links.

Is there a way to remove hreflang when there is only one language on a prestashop website ?

 

Thanks

Share this post


Link to post
Share on other sites

  • 2 weeks later...
  • 1 month later...
  • 1 month later...

Hello,

I have this problem: I use a multistore on my site for our different trades. It is also translated into 3 languages. CMS pages are common to all stores. And so it's duplicated.

https://www.audacieuse-galerie.ch/en/content/48-concept-of-fashion-and-images

https://www.audacieuse-galerie.ch/photographie-artistique/en/content/48-concept-of-fashion-and-images

Do you have a bit of code for these cms pages to be marked with a canonical tag? A canonical which redirects to the default store for cms pages? 

I will be very grateful to you.

Best regards

 

Edited by letonton (see edit history)

Share this post


Link to post
Share on other sites

  • 5 months later...
On 4/12/2019 at 10:59, SED Web said:

Oye, veo que nadie trabajó en la migración a 1.7.

Por cierto: ¿algún otro módulo válido que haga lo mismo con 1.7? ¿Algo en Prestashop Addons tal vez?

Gracias, que tengas un gran día.

Mirco

hi, may this module work for you for this topic

Share this post


Link to post
Share on other sites

  • 1 month later...
  • 5 months later...

Hello,

The hreflang causes small problems with the translation in the category. The generated links are not translated, which the link creates systematic a redirection 301. And this is not very good. Is it possible to correct?

       case 'category':
                $idCategory = (int) Tools::getValue('id_category');
                $content .= $this->getRelPrevNext('category', $idCategory);
                $canonical = $this->context->link->getCategoryLink((int) $idCategory);
                $hreflang = $this->getHrefLang('category', $idCategory, $languages, $defaultLang);
                break;

I think this is what has its limits. But how to define more precisely GetHreflang?

Best regards

 

Share this post


Link to post
Share on other sites

Its canonical and hreflang for free module smartblog: 

        case 'details':
                if(Configuration::get('smartblogurlpattern') != 1) {
                    $postId = Tools::getValue('id_post');
                } else {
                    $SmartBlog = new smartblog();
                    $slug = Tools::getValue('slug');
                    $postId = $SmartBlog->slug2id($slug);
                }

                $listDescs = Db::getInstance()->executeS('SELECT * FROM ' . _DB_PREFIX_ . 'smart_blog_post_lang WHERE id_smart_blog_post = \'' . $postId . '\'');

                foreach (Language::getLanguages(true, $this->context->shop->id) as $siteLangs) {
                    $langs[] = '/' . $siteLangs['iso_code'] . '/';

                    if ($siteLangs['id_lang'] == Configuration::get('PS_LANG_DEFAULT')) {
                        $defaultLang = '/' . $siteLangs['iso_code'] . '/';
                        $defaultLangIso = $siteLangs['iso_code'];
                    }
                }

                foreach ($listDescs as $postData) {
                    if ($postData['id_lang'] == Context::getContext()->language->id) {
                        if(Configuration::get('smartblogurlpattern') != 1) {
                            $postSlug = $postId . '_' . $postData['link_rewrite'];
                        } else {
                            $postSlug = Tools::getValue('slug');
                        }
                    }
                }

                $canonical = str_replace('.html', '', smartblog::GetSmartBlogLink('smartblog')) . '/' . $postSlug . '.html';
                $langs = array_unique($langs);

                foreach ($listDescs as $blogDesc) {
                    foreach (Language::getLanguages(true, $this->context->shop->id) as $siteLangs) {
                        if ($blogDesc['id_lang'] == $siteLangs['id_lang']) {
                            $linkBuild = str_replace($langs, '/' . $siteLangs['iso_code'] . '/', '<link rel="alternate" href="' . $canonical . '" hreflang="' . $siteLangs['iso_code'] . '">');

                            if(Configuration::get('smartblogurlpattern') != 1) {
                                $linkBuild = str_replace($postSlug, $postId . '_' . $blogDesc['link_rewrite'], $linkBuild);
                            } else {
                                $linkBuild = str_replace($postSlug, $blogDesc['link_rewrite'], $linkBuild);
                            }
                            
                            if ($siteLangs['iso_code'] == $defaultLangIso) {
                                if(Configuration::get('smartblogurlpattern') != 1) {
                                    $rew = str_replace($postSlug, $postId . '_' . $blogDesc['link_rewrite'], $canonical);
                                } else {
                                    $rew = str_replace($postSlug, $blogDesc['link_rewrite'], $canonical);
                                }  
                            }

                            $hreflang[] = $linkBuild;
                        }
                    }
                }

                $hreflang[] = str_replace($langs, $defaultLang, '<link rel="alternate" href="' . $rew . '" hreflang="x-default">');
                $hreflang = array_unique($hreflang);
                break;

it's fonctionnel for me.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More