I'm using groupblog feature and hence multisite is required with it .

If a new user(not logged in) reaches any of the groupblog directly viz. a subsite and clicks the login button he's redirected to www.mainsite.com/subsite/wp-login.php whereas i want him to reach at www.mainsite.com/wp-login.php . How can i do this ?


I suppose www.mainsite.com is the main blog and www.mainsite.com/subtitle is a dynamic child blog. You can use MU api for this:

add_action("init", function(){
    global $pagenow;

    if ( 'wp-login.php' !== $pagenow ) return;

    global $blog_id;

    $main_blog_ID = 1; // main site ID (use get_current_blog_id() to get ID)

    if ( (int) $blog_id !== (int) $main_blog_ID ) {
        switch_to_blog( $main_blog_ID );
        wp_redirect( wp_login_url() );

Hope that helps.

  • Where do I paste this code ? I'm not too much of acquainted with wordpress development . Thanks a lot :-)
    – roark
    Nov 23 '16 at 3:21
  • The code shall reside in your child theme's functions.php file, or in a custom plugin that is active all over the network. You are welcome. Please accept my answer if it helped :)
    – Ismail
    Nov 23 '16 at 10:40
  • Can you help me a bit more ::: As there are multiple blogs in my network so I want to add a follow button on each blog so that whenever someone posts something on his blog the followers get a notification sort of thing or they see the article in their news feed
    – roark
    Nov 23 '16 at 17:10
  • Don't you think there are ready plugins for this purpose? e.g Jetpack, just search for follow blog and such keywords for plugins.. Because this will require more code and work
    – Ismail
    Nov 23 '16 at 17:17

You could also do something like this -- which is similar to the above option, but persists some options through and uses a better action and some more salient functions:


 * Plugin Name: Multisite Login Consolidation
 * Author: georgestephanis
 * License: GPLv2+
 * Requires PHP: 7
 * Network: true

add_action( 'login_init', function() {
    if ( ! is_multisite() ) {
    if ( ! is_main_site() ) {
        switch_to_blog( get_main_site_id() );
        wp_safe_redirect( wp_login_url( $_REQUEST['redirect_to'] ?? null ) );
} );

Here it is in a gist if that's easier to download the file off of. It should be able to be installed and network activated pretty simply.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.