I'm attempting to create a Twitter style stream, so basically just index, a tag archive, and maybe a page or two while prohibiting access to everything else. For instance, they try to access a single post page and are tossed back to home. Is this appropriate use of redirects and wp_redirect, and if so, would it be better to create a dummy file (single.php for instance) that only contains wp_redirect or just use conditionals at the top of my header.php? Or am I totally off course?

  • I think redirects are fine for somethings but as a user I want to know WHY I'm being redirected. So I might suggest adding a "sorry you can't go there" page with say a 10 second time out then send them back home.
    – Brooke.
    Oct 4, 2011 at 7:15

2 Answers 2


It seems this would just be a function of your theme. If you don't provide links to single posts, categories, etc., then as far as your visitors are concerned, those things effectively don't exist.

If you really want to prevent access to things, you can't redirect in a template as headers have already been sent. You could maybe add an action to pre_get_posts, inspect the query, and redirect at that point.

Here's a simple example:

function wpse30196_pre_get_posts( $query ) {
    if( $query->is_home || $query->is_tag ):
        wp_redirect( home_url() );
add_action('pre_get_posts', 'wpse30196_pre_get_posts');

wp_redirect() does not exit automatically and should almost always be followed by exit.

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.