Is there a way to disable single post page, for example when some tries to go to single post page to show 404 page.
-
1Just out of curiosity ... why?– EAMannCommented 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.– user1147Commented Mar 9, 2012 at 1:03
-
Not sure if a 404 is the best idea. Simply remove all links to single post views.– kaiserCommented 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.– user1147Commented Mar 9, 2012 at 13:12
Add a comment
|
1 Answer
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;
}
}
-
1For pages & attachments, you can switch to
$query->is_singular();
.– kaiserCommented 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.– user1147Commented 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– user1147Commented Mar 9, 2012 at 15:41