Next Page URL in <head>

I am trying to add the next page URL within the of the page. Since it depends on Pagination, I have use the following code to generate what is needed to go into the . However, this code works at the bottom of the page where Pagination is defined but when I move to the it does not work.

Can someone point me in the right direction please?

{{ $pag := $.Paginator }}
{{ if gt $pag.TotalPages 1 }}
{{ $.Scratch.Set "dot_rendered" false }}
        {{ if $pag.HasNext }}
            <link href="{{ $pag.Next.URL | absURL }}" rel="next" />
        {{ end }}
{{ end }}


Apart from you not needing it anymore (see Google apologizes for rel=next/prev mixup) β€” Page variables should be your friend:

.Next and .Prev

And please don’t start the discussion about usefulness of rel="next|prev" β€” I support both sides :wink:

1 Like

Also look at .PrevInSection. That might be more helpful for your case, as it not links the next in date or order, but the next in date or order inside of a section (like a blog).

1 Like

Thank you, I will look into those info you have provided.