SEO fix to add page number to canonical link to listing pages pagination

Top Contributor
{% if current_page_num>1 %}
<link rel="canonical" href="{{ content.absolute_url }}/page/{{ current_page_num }}"> {% else %} {% if request.path is string_containing '/all' %} <link rel="canonical" href="{{ content.absolute_url }}/all"> {% else %} <link rel="canonical" href="{{ content.absolute_url }}">
{% endif %} {% endif %}

This code help our company to remove all the duplicate content errors on our MOZ report

If this post helped you resolve your issue, please consider marking it as the solution. Thank you for supporting our HubSpot community.
2 Replies 2
Community Manager

Hi @prosa 


Thank you for sharing this information 🙂




¿Sabías que la Comunidad está disponible en Español?
¡Participa hoy en conversaciones en el idioma de tu preferencia,cambiando el idioma en tus configuraciones!

Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !


Hello @prosa,


I'd also like to add this version if you are interested:

<!-- `is_listing_view` is a HubL variable in the developer info pane that checks if the page is a listing view such as blog listing page -->
{% if is_listing_view %}

	<!-- Add Canonical to paginated pages, topics, authors, and main blog listing page -->
	<link rel="canonical" href="{{canonical_url}}">

	<!-- Nested IF statement. -->
 	{% if current_page_num > 1 %}
	    //Append page num to title so you don't have duplicate title tags
	    document.title += " | Page {{current_page_num}}";
	    // Replace Current Meta Description with new one that appends page num before it.
	    document.querySelector('meta[name="description"]').setAttribute("content","Page {{current_page_num}} - {{content.meta_description|escapejs}}");

	{% endif %}
	<!-- /Nested IF Statement -->

{% endif %}
<!-- /End listing view IF -->

Your code should fix pagination issues but you also may want to change duplicate titles and descriptions. Please let me know what you think about this? We have implimented this fix and it works like a charm.

Reference this for more info: