A
A
Andrey Borchik2020-11-13 20:28:03
Prestashop
Andrey Borchik, 2020-11-13 20:28:03

How to set rel="canonical" for Prestashop website?

Arthata.by site on cms Prestashop 1.5
Task: to register rel="canonical" tags for pages

Implemented using the code in header.tpl:

{if $page_name == 'category'}
    <link rel="canonical" href="{$link->getCategoryLink($smarty.get.id_category, null, $id_lang,null,null )}" />    
    {if $languages|@count > 1}{foreach $languages as $lang}<link rel="alternate" hreflang="{$lang.iso_code}" href="{$link->getCategoryLink($smarty.get.id_category, null, $lang.id_lang,null,null )}" />{/foreach}{/if}
    {if $start!=$stop}{if $p != 1 && $p_previous != 1}{assign var='p_previous' value=$p-1}
    <link rel="prev" href="{$link->getCategoryLink($smarty.get.id_category, null, $id_lang,null,null )}{$link->goPage($requestPage, $p_previous)}" />{/if}
    {if $pages_nb > 1 AND $p != $pages_nb}{assign var='p_next' value=$p+1}
    <link rel="next" href="{$link->getCategoryLink($smarty.get.id_category, null, $id_lang,null,null )}{$link->goPage($requestPage, $p_next)}" />{/if}{/if}
    {/if}
    {if $page_name == 'product'}    
    <link rel="canonical" href="{$link->getProductLink($smarty.get.id_product, null, null, null, $id_lang, null, 0, false)}" />    
    {if $languages|@count > 1}{foreach $languages as $lang}<link rel="alternate" hreflang="{$lang.iso_code}" href="{$link->getProductLink($smarty.get.id_product, null, null, null, $lang.id_lang, null, 0, false)}" />{/foreach}{/if} 
    {/if}
    {if $page_name == 'cms' && $smarty.get.id_cms > 0}
    <link rel="canonical" href="{$link->getCMSLink($smarty.get.id_cms, null, false, $id_lang)}" />
    {if $languages|@count > 1}{foreach $languages as $lang}<link rel="alternate" hreflang="{$lang.iso_code}" href="{$link->getCMSLink($smarty.get.id_cms, null, false, $lang.id_lang)}" />{/foreach}{/if}
    {/if}
    {if $page_name == 'manufacturer' && $smarty.get.id_manufacturer > 0}
    <link rel="canonical" href="{$link->getManufacturerLink($smarty.get.id_manufacturer, null, $id_lang)}" />    
    {if $languages|@count > 1}{foreach $languages as $lang}<link rel="alternate" hreflang="{$lang.iso_code}" href="{$link->getManufacturerLink($smarty.get.id_manufacturer, null, $lang.id_lang)}" />{/foreach}{/if}
    {/if}
    {if $page_name == 'manufacturer' && !isset($smarty.get.id_manufacturer)}
    <link rel="canonical" href="{$link->getPageLink('manufacturer', 'true', $id_lang)}" />    
    {if $languages|@count > 1}{foreach $languages as $lang}<link rel="alternate" hreflang="{$lang.iso_code}" href="{$link->getPageLink('manufacturer', 'true', $lang.id_lang)}" />{/foreach}{/if}
    {/if}
    {if $page_name == 'index'}
    <link rel="canonical" href="{$link->getPageLink('index', 'true', $id_lang)}" />    
    {if $languages|@count > 1}{foreach $languages as $lang}<link rel="alternate" hreflang="{$lang.iso_code}" href="{$link->getPageLink('index', 'true', $lang.id_lang)}" />{/foreach}{/if}
    {/if}


Everything works except for one little thing. A site with SSL and links all of the form https
But for some reason this code generates rel="canonical" with a link of the form http

<link rel="canonical" href="http://arthata.by/">
How to fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
ITLandgraf, 2020-11-14
@ITLandgraf

I would look at the code of the getCategoryLink, getProductLink and other functions. They do not handle SSL correctly.

A
Alexey, 2022-01-07
@Stroy-St

Hey!
Site Stroy-St.Ru on cms Prestashop 1.6.1.24 I inserted
this code into the header.tpl of my site. Site with SSL.
The main page of the site, manufacturers' pages, product category pages and product pages received rel="canonical" with a link like https . Fine!
But the "my site/content/my page" CMS pages got rel="canonical" with a link like http .
As a result of trial and error, editing the code in different files, using the "poke" method, I fixed this error in this way:
In the line of your code

<link rel="canonical" href="{$link->getCMSLink($smarty.get.id_cms, null, false, $id_lang)}" />

Changed false to true
<link rel="canonical" href="{$link->getCMSLink($smarty.get.id_cms, null, true, $id_lang)}" />

And links on CMS pages got rel="canonical" like https .
How do you think so right?
And another question other pages, such as:
my site/content/category/my page
https://stroy-st.ru/feedback
https://stroy-st.ru/sitemap
https://stroy-st.ru/ maps
https://stroy-st.ru/new-products
Pages of modules and many others
Didn't get the rel="canonical" link at all.
Please tell me how to generate code for these pages too.
Thank you!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question