0

Is there a way to prevent people from visiting a post's permalink?

A lot of times we create posts or custom post types that end up being included as part of the content of a page or some other feature and are not always intended to be viewed individually.

A good example might be for a slideshow. You create a few posts where each individual post is the content of a slide in the slideshow. Each one of those posts has a unique permalink, something like example.com/slide-one. There's no reason for someone to be able to access that individual post so I would like to "hide" it.

1

If you don't expose the permalinks on the front end, then there's no way for someone to reach them, but if you want to absolutely prevent it then set publicly_queryable to false when you register your post type.

  • Though someone could guess the URL. But I guess that doesn't matter if the content is being exposed elsewhere on the website. What about the default post type? I might want to make some available and not others (probably through a category or tag). Then where do I go from there? Hook into template_redirect? – hungerstar Sep 13 '13 at 4:43
  • template_redirect would work, check if is_single(), fetch and check the categories or tags for the post, and maybe wp_redirect( home_url() ); to send people away. – Milo Sep 13 '13 at 4:54

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.