Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
1  
Just out of curiosity ... why? –  EAMann Mar 9 '12 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 Mar 9 '12 at 1:03
    
Not sure if a 404 is the best idea. Simply remove all links to single post views. –  kaiser Mar 9 '12 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 Mar 9 '12 at 13:12

1 Answer 1

up vote 8 down vote accepted

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;
}
share|improve this answer
    
For pages & attachments, you can switch to $query->is_singular();. –  kaiser Mar 9 '12 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 Mar 9 '12 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. –  helenhousandi Mar 9 '12 at 15:39
    
@helenhousandi Hey, yes, it is different question, but still I got my answer. Thank you –  user1147 Mar 9 '12 at 15:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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