Web Hosting from Bluehost. Sign-up here

Page numbers in page titles and meta descriptions

Posted on by Clive Walker in Perch Code Snippet

I want to output page numbers (and a separator character) in the page code for paginated pages on this site. Mostly, I want to do this so that the pages have different page titles and meta descriptions. And so that I don't get page duplication or same page title/description warnings from Google in my Search Console account.

I use this PHP snippet:

<?php if(isset($_GET['page'])) echo " | page ". $_GET['page'];  //outputs page number ?>

This checks that the page number value is in the query string and outputs it and a separator " | " wherever I want.

If using Perch CMS, you can echo the page number like this:

<?php echo intval(perch_get('page')); ?>

... although this will output "0" on the very first page as well. You may not want this so you will need to check for that and amend the code accordingly.

Leave a comment

A simple question that helps prevent automated form fillers.

© 2017 Clive Walker