Tomi14 Posted December 6, 2022 Share Posted December 6, 2022 (edited) How to set up canonical URL for homepage? I have missing canonical URL for few pages on my site (8 pages from ~100). But one of them is homepage:( If I check source it look: script type= text/javascript" ...date_format_full":"Y-m-d H:i:s","id":2},"page":{"title":"","canonical":null,"meta":{"title":"Domofony Vidos - Sklep z wideodomofonami VIDOS","description... How to fix this part: canonical":null? Link: Vidos Domofony Edited December 6, 2022 by Tomi14 (see edit history) Link to comment Share on other sites More sharing options...
VisualX Posted January 31, 2023 Share Posted January 31, 2023 Hello! Did you found a solution for this? If yes, please share Thanks Link to comment Share on other sites More sharing options...
Tomi14 Posted February 5, 2023 Author Share Posted February 5, 2023 (edited) I added this line to header.tpl. I think it should work only for main page, but i don't have time to check it. Maybe there is a better solution, but I don't know how Quote {include file="_partials/header-layout/header_type_1.tpl" } <meta name="robots" content="index,follow"> <meta name="author" content="Vidos-Domofony"> <link rel="canonical" href="https://vidos-domofony.pl/"> Edited February 5, 2023 by Tomi14 (see edit history) Link to comment Share on other sites More sharing options...
elisolution Posted June 5, 2023 Share Posted June 5, 2023 I added in /public_html/themes/XXXX/templates/_partials/head.tpl lines 42-43: {if $page.canonical = 'null'} <link rel="canonical" href="https://mysite.com"> {/if} It work vey well 1 Link to comment Share on other sites More sharing options...
Tomi14 Posted June 6, 2023 Author Share Posted June 6, 2023 Thanks! Link to comment Share on other sites More sharing options...
LarsM Posted August 28, 2023 Share Posted August 28, 2023 (edited) I had the same issue in PrestaShop 8.1.1 and made this solution: In the file: /themes/XXXX/templates/_partials/head.tpl I changed this (lines 42-44): {if $page.canonical} <link rel="canonical" href="{$page.canonical}"> {/if} To this: {if $page.canonical} <link rel="canonical" href="{$page.canonical}"> {elseif $page.page_name == 'index'} <link rel="canonical" href="https://{$smarty.server.HTTP_HOST}/"> {/if} In additon to elisolution's answer above, this also checks whether we are actually on the home page (not just whether the canonical was set or not). I tested this solution a bit and as far as I can see, it works as expected. Otherwise, please let me know! Thanks PS: Remember to change "https" to "http" if your site isn't handling requests through the HTTPS protocol. You could fiddle with variables like $smarty.server.REQUEST_SCHEME or $smarty.server.HTTPS to check automatically, but it seemed like overkill to me, as I always use the HTTPS protocol on my websites these days. Edited August 28, 2023 by LarsM (see edit history) 1 Link to comment Share on other sites More sharing options...
elisolution Posted September 17, 2023 Share Posted September 17, 2023 On 6/5/2023 at 6:33 PM, elisolution said: I added in /public_html/themes/XXXX/templates/_partials/head.tpl lines 42-43: {if $page.canonical = 'null'} <link rel="canonical" href="https://mysite.com"> {/if} It work vey well I changed it in this way because It works better 👇: {if $page.canonical} <link rel="canonical" href="{$page.canonical}"> {elseif $page.canonical = 'index'} <link rel="canonical" href="https://mysite.com"> {/if} Link to comment Share on other sites More sharing options...
Hart Posted November 2, 2023 Share Posted November 2, 2023 to implement the canonical for multilanguage use this code: {if $page.canonical} <link rel="canonical" href="{$page.canonical}"> {elseif $page.page_name == 'index'} <link rel="canonical" href="{$smarty.server.SCRIPT_URI}"> {/if} 1 Link to comment Share on other sites More sharing options...
Tomi14 Posted November 17, 2023 Author Share Posted November 17, 2023 (edited) On 9/17/2023 at 3:15 PM, elisolution said: I changed it in this way because It works better 👇: {if $page.canonical} <link rel="canonical" href="{$page.canonical}"> {elseif $page.canonical = 'index'} <link rel="canonical" href="https://vidos-domofony.pl"> {/if} With this, now I have 14 pages with Canonicalised errors. Do you have any idea how to fix it? Most of this pages are sites, from help category: https://vidos-domofony.pl/category/9-pomoc With homepage your solutions works great On 8/28/2023 at 3:19 PM, LarsM said: I had the same issue in PrestaShop 8.1.1 and made this solution: In the file: /themes/XXXX/templates/_partials/head.tpl I changed this (lines 42-44): {if $page.canonical} <link rel="canonical" href="{$page.canonical}"> {/if} To this: {if $page.canonical} <link rel="canonical" href="{$page.canonical}"> {elseif $page.page_name == 'index'} <link rel="canonical" href="https://{$smarty.server.HTTP_HOST}/"> {/if} In additon to elisolution's answer above, this also checks whether we are actually on the home page (not just whether the canonical was set or not). I tested this solution a bit and as far as I can see, it works as expected. Otherwise, please let me know! Thanks PS: Remember to change "https" to "http" if your site isn't handling requests through the HTTPS protocol. You could fiddle with variables like $smarty.server.REQUEST_SCHEME or $smarty.server.HTTPS to check automatically, but it seemed like overkill to me, as I always use the HTTPS protocol on my websites these days. But with this, I have only 7 Canonicals missing Edited November 17, 2023 by Tomi14 (see edit history) Link to comment Share on other sites More sharing options...
eugenata Posted January 31 Share Posted January 31 Hi! If you want have canonical in all pages use thtis varible for current web address (the url of the page viewing) in head.php {$urls.current_url} so: {block name='head_seo_canonical'} {if $page.canonical} <link rel="canonical" href="{$page.canonical}"> {else} <link rel="canonical" href="{$urls.current_url}"> {/if} {/block} But remember that canonical url need only for page that have possible duplicated. index, contact, cms pages, new product and other list pages, can never possible have duplicated, becouse are like static pages, not like catalog pages. Bye Link to comment Share on other sites More sharing options...
Betz Developer Posted May 17 Share Posted May 17 After some researching and testing, my current solution in my `head.tpl` looks like this: {block name='head_seo_canonical'} {if $page.canonical != ''} <link rel="canonical" href="{$page.canonical}"> {elseif $smarty.server.SCRIPT_URI != ''} <link rel="canonical" href="{$smarty.server.SCRIPT_URI}"> {elseif $smarty.server.REDIRECT_URL != ''} <link rel="canonical" href="{$smarty.server.REDIRECT_URL}"> {else} <link rel="canonical" href="{$urls.current_url}"> {/if} {/block} Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now