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
alevikx
(Ashish Kumar)
July 5, 2021, 7:13am
2
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
alevikx
(Ashish Kumar)
July 5, 2021, 7:48am
3
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
shamir01
(Shamir Allibhai)
May 17, 2022, 3:29pm
4
thanks @alevikx
Did you place this in the ?
Do you have a site that has this example live?