How can I remove the next and previous links in a custom post type archive page, but only for that post type?

I know I could wrap any function in if ( get_post_type($post) == 'myposttype' ) {} but I can't find a solid snippet to remove the pagination.

I have tried a few solutions, this being one of them, but nothing is working. And yes, I did try removing them from my template. :)

next page link

  • 1
    What should happen if there are more than 10 (or whatever "posts per page" setting you are using) posts of that CPT? Does the archive page show all, or would you want the number of posts constrained? Also, are you using archive.php for your CPTs, or do you have specific archive-cptname.php templates set up? – chrishajer Jul 15 '11 at 17:56
  • I still want the archive page to show, just remove the next/previous links. If the post type has more than 10 posts, do nothing. If it has less than 10, do nothing. Either way display the content of the archive-posttype template. I'm actually using the twentyeleven style setup where it the content-posttype.php template is called by archive.php. – m-torin Jul 15 '11 at 20:04

Got it figured out...

While I did manually remove the next page links, CloudFlare's cache was not playing nice.

| improve this answer | |

This will visually remove it from the page (but the links will still be in the HTML):

Use the class on the tag to use a CSS selector to set the Next/Previoius link CSS to "display:none"

body.post-type #nav-below {
| improve this answer | |
  • While that does remove the link visually, it doesn't remove it from the code... <nav id="postfooternav"><p><a href="http://url.com/archive/page/2" >Next Page &raquo;</a></p></nav> – m-torin Jul 15 '11 at 17:27
  • I agree - I thought you were mostly concerned with the visual aspect. – GavinR Jul 18 '11 at 16:19

Easiest way: open your archives.php template (or index.php if no archives.php) and copy it over to a new template and name it "archives-{post-type-name}.php", then open it and remove the pagination function.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.