1

Is there a way to disable single post page, for example when some tries to go to single post page to show 404 page.

4
  • 1
    Just out of curiosity ... why?
    – EAMann
    Commented Mar 9, 2012 at 0:52
  • @EAMann hi, it is because, I do not need single page, but I need post content to display in widget. Just wondering is there a way to disable single page.
    – user1147
    Commented Mar 9, 2012 at 1:03
  • Not sure if a 404 is the best idea. Simply remove all links to single post views.
    – kaiser
    Commented Mar 9, 2012 at 10:38
  • @kaiser Hi, I do not have links to that single post, but if I do not show 404 than I'll need to setup so google doesn't index these pages, I'm not sure what is the best idea, because here is SEO also good question.
    – user1147
    Commented Mar 9, 2012 at 13:12

1 Answer 1

9

Although I'm also curious as to why you'd want to do this, and would probably suggest using a custom post type instead, this would probably work (actually works for any single post type except pages and attachments):

add_action( 'pre_get_posts', 'wpse44983_single_post_404' );
function wpse44983_single_post_404( $query ) {
    if ( $query->is_main_query() && $query->is_single() ) {
        $query->is_404 = true;
     }
}
4
  • 1
    For pages & attachments, you can switch to $query->is_singular();.
    – kaiser
    Commented Mar 9, 2012 at 10:38
  • @helenhousandi Hi, thank you for response, this is also what have I tried, it works, my question is I'm just wondering how will this affect SEO.
    – user1147
    Commented Mar 9, 2012 at 13:14
  • @user1147 That sounds like a completely different question, and one that isn't relevant to WordPress itself and should probably be asked elsewhere. Commented Mar 9, 2012 at 15:39
  • @helenhousandi Hey, yes, it is different question, but still I got my answer. Thank you
    – user1147
    Commented Mar 9, 2012 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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