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.

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?

share|improve this question
    
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. –  BandonRandon Oct 4 '11 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 ):
        return;
    else:
        wp_redirect( home_url() );
        exit;
    endif;
}
add_action('pre_get_posts', 'wpse30196_pre_get_posts');
share|improve this answer

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

share|improve this answer

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.