-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pagination: Include pager number in pager's Permalink/RelPermalink values #4507
Comments
This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help. |
Still applicable for Hugo v0.44 |
This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help. |
Still applicable for Hugo v0.51 |
This is very important issue for larger website, since wrong canonical on pagination pages prevents from proper crawling and indexing, which leads to lower organic traffic. |
I was looking for a way to access the permalink for paginated pages when I came across this issue. It would certainly be great to have a There was a useful article that helped with manually constructing paginated permalinks, but it only worked on a site's homepage and it failed if The following may be useful to others looking to access a permalink that should mirror the paginated page's URL. I've tested it on paginated taxonomy lists, post/article lists, the home page, and elsewhere, and it seems to always produce the correct permalink. If you're not using ugly URLs and a modified paginate path, you can use the following:
{{ $paginator := .Paginate (where .Site.RegularPages ".Params.post" "!=" false) }}
{{ $permalink := .Permalink }}
{{ with $paginator }}
{{ if and (or $.IsHome $.IsNode) (ne .PageNumber 1) }}
{{ $permalink = print $permalink "page/" .PageNumber "/" }}
{{ end }}
{{ end }} When
{{ $uglyURLs := $.Param "uglyURLs" | default false }}
{{ $paginatePath := $.Param "paginatePath" | default "page" }}
{{ $paginator := .Paginate (where .Site.RegularPages ".Params.post" "!=" false) }}
{{ $permalink := .Permalink }}
{{ with $paginator }}
{{ if and (or $.IsHome $.IsNode) (ne .PageNumber 1) }}
{{ $permalink = print $permalink $paginatePath "/" .PageNumber (cond $uglyURLs ".html" "/") }}
{{ end }}
{{ end }} |
From Google's documentation, last updated 2021-11-22, emphasis in original:
|
@bep web.dev has started to issue a warning for this and penalizing in SEO score. (None of the suggested workarounds I found here and online works).
|
This issue has had me scratching my head for days! This, coupled with the fact that Hugo caches the first instance of |
Hopefully this will be resolved in nearest future. According to all SEO guides I found, pagination pages should have self-referring canonicals nowadays. While there are several articles on workarounds in hugo forum, they are quite hard to implement in some situations. I ended up disabling canonical header in my theme and using JS for this, as described here - https://developers.google.com/search/docs/crawling-indexing/javascript/javascript-seo-basics#properly-inject-canonical-links It's also possible to use HTTP headers which maybe even better than JS - https://developers.google.com/search/docs/crawling-indexing/consolidate-duplicate-urls#rel-canonical-header-method |
It also affects the tag
|
Just for reference, I used to use this to determine the permalink:
Unfortunately, for me, this has unintended side effects like resetting the sorting on the paginator and creating paginated 404 pages. So it's not a real solution. (I am still looking for a solution.) |
This is still an issue, and it needs to be fixed. |
I found a descent work-around in https://github.com/calintat/minimal/pull/122/files |
Here's the best solution I found in the discourse forum...
But you must ensure that the |
/page/:number
part in paginated list templates
Simple example:
Although https://discourse.gohugo.io/t/control-pagination-and-page-collections-from-baseof-html/37643/8 In the above, you have to control all pagination from the top of your baseof.html template. That way you can access the |
@somethingSTRANGE This won't work in every case as #2449 introduced multilang support for
I therefore quickly hacked a partial which uses regular expressions to get the paginatePath:
Not really nice, but works... |
This is a much simpler approach: |
These workarounds are not generic enough. It should be done in the underlying "framework" (in Hugo) instead. |
Example:
In the
https://example.com/blog/page/2/
page, the.Permalink
is set tohttps://example.com/blog/
.Shouldn't
.Permalink
be set tohttps://example.com/blog/page/2
?Or is this by design?
Use case:
Quoted from Pagination & SEO: best practices:
If the
.Permalink
is set tohttps://example.com/blog/page/:number
on paginated list templates, using the following code for includinglink(rel=canonical)
tag to the HTMLhead
would follow the best practice by default.Otherwise, with the current
.Permalink
implementation, we have to come up with hacks that include checking if it's a list template and then extract the page number from the paginator pages.The text was updated successfully, but these errors were encountered: