Home wordpress How to remove pagination from your post titles in a specific WordPress template
How to remove pagination from your post titles in a specific WordPress template

How to remove pagination from your post titles in a specific WordPress template


Okay, so I have been beating my head against the wall for a week or so now trying to figure out how I can fix the product page titles at virtuabotix.com so that the – Page ##### wouldn’t show up in the post title.

This all started when I put together a fake post generation set up to make more SEO friendly URL structuring for our products a few weeks back. All in all the changes have worked out great, and I can’t wait to share a few guides on how to do similar stuff with your own WordPress Blog or Webstore. That said, the UPC codes for most products were quite annoyingly being interpreted as page numbers as if the product pages were split into a couple hundred billion individual pages (I mean really page 609224532030) seems a little unrealistic for a page number right?

I tried and tried to find a way to change the page number itself so that WordPress never got to the point where it considered the page to be anything other than zero for all pages that used our product page templates, but as you can guess I had no luck with that methodology. (Please let me know in the comments if you have a more awesome way to do this).

My solution required changes in two spots, but seems to operate quite efficiently, and could likely be used to make lot’s of other template dependent page title changes in your blog.

Make these changes to thetag in your header.php (found in your theme folder)

<?php global $DONOTPAGEMEPLEASE; //this will also be defined and set in our template if(!$DONOTPAGEMEPLEASE) wp_title(""); //outputs an unchanged title else { //pull title for processing as indicated by the false passed into the wp_title function $mytitle=wp_title("",false); //we take everything in the title before the page number $mytitle = substr($mytitle, 0, strpos($mytitle, " - Page ")); echo $mytitle;//and we echo it out to the browser } ?>

As you can see above we are looking for the $DONOTPAGEMEPLEASE variable, which we will be setting up in our next file to make it so that pagination still works properly on all other WordPress templates. Notice that the Page number is only removed if the variable is true.

Next we add the following code to our template file (usually found in the templates folder in your WordPress Theme). Be sure to put this code at the very top of the template above get_header() function.

//be sure to put these two lines above the get_header() call
//only put this on a template where pagination in titles is undesirable.

There you have it! With these simple changes you can now decide whether or not the page number should be automatically added to your template. Obviously use this trick with care, since the overwhelming majority of WordPress blogs will want to leave their title pagination intact. But if you are crazy like me, then I hope this guide helped to save you some time.

Joseph Dattilo Writer, Electrical Engineer, CEO and founder of Virtuabotix LLC, and completely crazy in every way.


Your email address will not be published. Required fields are marked *