Why does Hugo show the home/section permalink instead of the paginated page e.g hugo.io/page/3
when I open page 3 in the canonical URL?
You are more likely to receive an accurate and timely response if you post a link to the public repository for your project.
See https://discourse.gohugo.io/t/requesting-help/9132.
Let us see your code
Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick
git clone
on your repo, then runhugo server
in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.
I added some clarification.
Not enough.
If I am on page 2, 3 etc, the canonical link remains like so in the HTML.
<link rel="canonical" href="https://example.com/dresses/" />
instead of
<link rel="canonical" href="https://example.com/dresses/page/3/" />
You are running into this:
https://github.com/gohugoio/hugo/issues/4507
This is a detailed description of the situation:
https://discourse.gohugo.io/t/determine-if-current-page-is-result-of-pagination/37494/4
The trick is to paginate before trying to access the pager number.
https://discourse.gohugo.io/t/control-pagination-and-page-collections-from-baseof-html/37643/8
The second topic includes a detailed example that you can clone and test.
I moved the $paginator
code in your baseof.html
to my head.html
file. But testing so far and the links work.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.