Indicating paginated pages with rel=“next” and rel=“prev”

Hello!

Does anyone know how to indicate rel=“next” and rel=“prev” on paginated pages? Failing that, a way to tell Google the primary URL for a paginated page using a canonical tag?

I know I can add a custom field on a CMS page to achieve canonical, but then your canonical tag would also be on the primary page. Would that matter?

Thanks

1 Like

I just faced this issue, fortunately, I know a little bit of jquery and can fix it through custom code. I’ll post the code once I figure out something

There you go!

<script>
$(document).ready(function(){
	var prev_link = window.location.origin + window.location.pathname + $('.w-pagination-previous').attr('href');
	var next_link = window.location.origin + window.location.pathname + $('.w-pagination-next').attr('href');

	if($('.w-pagination-previous').attr('href')){
		prev_canonical =  "<link rel='prev' href='" + prev_link.toString() +"' />";
		$('body').append(prev_canonical);
	}

	if($('.w-pagination-next').attr('href')){
		next_canonical =  "<link rel='next' href='" + next_link.toString() +"' />";
		$('body').append(next_canonical);
	} 
});
</script>
1 Like

thanks @alevikx

Did you place this in the ?
Do you have a site that has this example live?