Redirect all users, except network administrators, from the main site to a subsite

The question:

I have a WP Multisite / Multi Network installation. What I need is to redirect all non-logged and also all logged in users, except logged in network administrators, from the main site (including all nested pages, posts, categories etc.) to the, that is a segregated multisite network. They share the same database. The network administrator will have access to the main site only after they will log in on the In this way, only the logged in network administrators must have access to the main site


The @seamus-leahy solution works, but only partially. I use his function in a multisite multi-networks installation and all networks in this configuration works like separated WP installations, so the network will not recognize and log in automatically the network administrator when he/she is already logged in on the (network 2), but logged out from the (network 1). This means that the network administrator, in this context, also cannot access the main network How to solve this?

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

You’ll need to tie into template_redirect hook where you will check the site and the user and then redirect if needed.

function redirect_to_subsite() {
    if( is_main_site() && !current_user_can('manage_network') ) {
        $blog_id = 5; // <<----- Update the ID to the subsite blog ID you want to redirect to
         wp_redirect( get_site_url( $blog_id ) );
 add_action( 'template_redirect', 'redirect_to_subsite' );

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment