Share Your Work

prosa
トップ投稿者

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

{% 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.
4件の返信
jimboroberts
投稿者 | Elite Partner
投稿者 | Elite Partner

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

HubSpot has this built into the platform now -> https://share.cleanshot.com/2YxVvs1H

 

If you go to Settings > Pages > SEO & Crawlers.


I hope this helps anyone else searching.

0 いいね!
Jhon
メンバー

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

Thanks, this was a great starting point! it didn't work exactly for our needs but i've modified it a bit to work, we intended to achieve:
--> <link rel="canonical" href="sample/blog/"> (for page 1, point to original page instead of the generated page 1 (duplicate))
--> <link rel="canonical" href="sample/blog/page/2"> (for page 2 and so on..) 

{% if is_listing_view %}
  {% if current_page_num == 1 %}
   <link rel="canonical" href="{{ content.absolute_url|cut("/page/1") }}">
  {% else %}
   <link rel="canonical" href="{{ content.absolute_url }}">
  {% endif %}
{% endif %}


also, if you have a simple list page it might be safer to do 
{% if simple_list_page %}
// instead of
{% if request.path is string_containing '/all' %}
// might have conflict if the page url has '/all...'

0 いいね!
ziadi
投稿者

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

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 %}
		<script>
	    //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}}");
    
  		</script>

	{% 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: https://www.wearediagram.com/blog/correcting-seo-issues-on-the-hubspot-cms

0 いいね!
sharonlicari
コミュニティーマネージャー
コミュニティーマネージャー

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

Hi @prosa 

 

Thank you for sharing this information 🙂

 

Best

Sharon


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




0 いいね!