Help to make canonical for staticpages, please

Found a bug? Tell us!!
Post Reply
Jekky
Regular
Posts: 21
Joined: Thu Jul 01, 2021 1:15 pm
Location: Russia
Contact:

Help to make canonical for staticpages, please

Post by Jekky » Wed Jan 19, 2022 8:33 am

Help to make canonical for staticpages, please. This is important for website optimization. Here is the main page of the series of articles on my website https://webshef.ru/pages/sistemi-pitaniya.html . It is made static and links are also to static pages. But there is no canonical anywhere and I can't find an opportunity to do this. A page without canonical on the internet today will not be evaluated by a search engine.

User avatar
onli
Regular
Posts: 2594
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Help to make canonical for staticpages, please

Post by onli » Wed Jan 19, 2022 4:17 pm

Thankfully, this is not true. Google for example will certainly index pages without a canonical - as that's only needed to avoid issues with duplicated content.

But that does not mean it would not be better to set it if the necessary data are available. For regular entries, the theme will do that work - see https://github.com/s9y/Serendipity/blob ... pl#L17-L22 as an example. But I have never added it to static pages. Would editing such a .tpl file be possible for you if we can present the extended code here? Are you certain you really need that feature?

Jekky
Regular
Posts: 21
Joined: Thu Jul 01, 2021 1:15 pm
Location: Russia
Contact:

Re: Help to make canonical for staticpages, please

Post by Jekky » Wed Jan 19, 2022 8:42 pm

onli wrote:
Wed Jan 19, 2022 4:17 pm
Thankfully, this is not true. Google for example will certainly index pages without a canonical - as that's only needed to avoid issues with duplicated content.

But that does not mean it would not be better to set it if the necessary data are available. For regular entries, the theme will do that work - see https://github.com/s9y/Serendipity/blob ... pl#L17-L22 as an example. But I have never added it to static pages. Would editing such a .tpl file be possible for you if we can present the extended code here? Are you certain you really need that feature?
With regular entryes everything is fine! It is necessary for static pages. Of course of course of course!!!! Need a code! Yes, I will work with tpl. A thousand thanks for the intention to help!))))

User avatar
onli
Regular
Posts: 2594
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Help to make canonical for staticpages, please

Post by onli » Sun Jan 23, 2022 12:19 pm

Okay, I have one approach you could try.

In the index.tpl of your theme (you can use the template editor plugin to edit it, it will also create a fork and thus make the change update proof) there should be these lines:

Code: Select all

{if ($view == "start")}
    <link rel="canonical" href="{$serendipityBaseURL}">
{/if}
Change them to this:

Code: Select all

{if ($view == "start") && ! isset($staticpage_permalink)}
    <link rel="canonical" href="{$serendipityBaseURL}">
{/if}
{if ($view == "start") && isset($staticpage_permalink)}
    <link rel="canonical" href="{$staticpage_permalink}">
{/if}
{if ($view == "plugin") && isset($staticpage_permalink)}
    <link rel="canonical" href="{$staticpage_permalink}">
{/if}
Actually, since there is no canonical on your static page so far it's possible the canonical is set different in your theme. In that case just add this part somewhere in the head section of the index.tpl:

Code: Select all

{if ($view == "start") && isset($staticpage_permalink)}
    <link rel="canonical" href="{$staticpage_permalink}">
{/if}
{if ($view == "plugin") && isset($staticpage_permalink)}
    <link rel="canonical" href="{$staticpage_permalink}">
{/if}
This should add the canonical as a relative url. Strange to me, but I checked and search engines are supposed to be fine with that. You might want to check that with an analysis tool, if a canonical appears with this change. But creating the real absolute url at that point would be a bit hard.

Jekky
Regular
Posts: 21
Joined: Thu Jul 01, 2021 1:15 pm
Location: Russia
Contact:

Re: Help to make canonical for staticpages, please

Post by Jekky » Mon Jan 24, 2022 3:34 pm

onli wrote:
Sun Jan 23, 2022 12:19 pm
Okay, I have one approach you could try.

In the index.tpl of your theme (you can use the template editor plugin to edit it, it will also create a fork and thus make the change update proof) there should be these lines:

Code: Select all

{if ($view == "start")}
    <link rel="canonical" href="{$serendipityBaseURL}">
{/if}
Change them to this:

Code: Select all

{if ($view == "start") && ! isset($staticpage_permalink)}
    <link rel="canonical" href="{$serendipityBaseURL}">
{/if}
{if ($view == "start") && isset($staticpage_permalink)}
    <link rel="canonical" href="{$staticpage_permalink}">
{/if}
{if ($view == "plugin") && isset($staticpage_permalink)}
    <link rel="canonical" href="{$staticpage_permalink}">
{/if}
Great! Thanks! It works! The first option worked right away!!:-) Now static pages have become canonical! Hurray!

Post Reply