Wordpress - Prevent access to single post types

The fast way

In your .htaccess add a rule

RedirectMatch Permanent ^/press/.+ /press/

Plugin way

Hook into template_redirect and redirect all requests to a single entry:

add_action( 'template_redirect', 'wpse_45164_redirect_press' );

function wpse_45164_redirect_press()
{
    if ( ! is_singular( 'press' ) )
        return;

    wp_redirect( get_post_type_archive_link( 'press' ), 301 );
    exit;
}

(Caveat: not tested)


An alternative to redirecting users would be to make it so this page isn't generated to begin with. Setting your post type to 'public' => false, 'publicly_queryable' => true will create a non-public post type. Then you can build a custom page template to act as the archive, with a custom query in the page template.

See the register_post_type function for more info.

Tags:

Redirect