Changing login url on all sites & the welcome message

I have seen posts on the different ways to change your login url and know there are some plugins.

I was wondering though, if you change the login url with htaccess will that also change the url on all your new sites that are created?

Then I guess you change the link the new users get in the welcome message in network settings and change it what ever you like.

  • Michelle Shull

    Hi George!

    On question #1, it depends. When users log in to your network, do they all log in on the main site, then navigate to the subsites, or do they login on the subsites themselves?

    If it's the latter, you could either create redirects for each subsite in htaccess, or you could keep user login strictly on the primary site.

    On the second question, yep, you can do that, exactly, or you can use a tool like our Ultimate Branding plugin to change the welcome message. (With the very cool site-wide text change tool)

    Hope this helps! Have a great Saturday, George!

  • George

    So there are many ways :slight_smile:
    If you use the htaccess method do you have to add a line for each new site or can you use some sort of wildcard to automatically do the same for each new sub-domain created?

    I just them logging at each subsite since that is the way it is in the default welcome message.

    I guess it be easier and look better if all users had one login.
    However, if they login on the main site, I would want them to redirect to the users site and not the main site.

    Thanks for the help :slight_smile:

  • Michael Bissett

    Hey @George,

    If you use the htaccess method do you have to add a line for each new site or can you use some sort of wildcard to automatically do the same for each new sub-domain created?

    I just them logging at each subsite since that is the way it is in the default welcome message.

    Nope, as a matter of fact, if you were to follow the method here:

    https://wordpress.org/support/topic/how-to-change-from-wp-loginphp-to-login

    (adding in the code in Step 2) as an mu-plugin, more on how to do that here)

    It would apply to all sites. :slight_smile:

    The only other thing you would have to do would be to modify the welcome email (Settings -> Network Settings -> Welcome Email), so that instead of this:

    Log in here: BLOG_URLwp-login.php

    It would say this:

    Log in here: BLOG_URLlogin

    I guess it be easier and look better if all users had one login.
    However, if they login on the main site, I would want them to redirect to the users site and not the main site.

    If you're wanting to do this, you'll want to make sure that the line I mentioned earlier:

    Log in here: BLOG_URLlogin

    Says something like this:

    Log in here: http://mainsite.com/login

    Then, you'll also want to add this code as an mu-plugin:

    <?php
    /*
    Plugin Name: Redirect To Users Primary Blog (modified version)
    Description: Redirect user to their their primary blog upon login
    Version: 1.0
    Author: Timothy Bowers, Aristeides Stathopoulos (original creators of code used in this plugin); Michael Bissett (tweaker of their code to provide end result)
    License: GNU General Public License (Version 2 - GPLv2)
    Network: true
    */
    
    function my_login_redirect( $redirect_to, $request, $user ){
      //is there a user to check?
      global $user;
    
      if ( $user ) {
        $user_id = $user->ID;
      }
    
      if ( isset( $user_id ) ) {
        // Get the blogs of this user
        $user_blogs = get_blogs_of_user( $user_id );
        // Get the URL of the blog
        foreach ( $user_blogs AS $user_blog ) {
          $primary_url = 'http://' .$user_blog->domain . '/';
          wp_redirect($primary_url . "wp-admin/");
          die();
        }
        // If user has no blog, return to the homepage.
      } else {
        return home_url();
      }
    }
    add_filter( "login_redirect", "my_login_redirect", 10, 3 );

    Code sourced from the following threads, hat tip to @aristath & @Timothy Bowers:

    https://premium.wpmudev.org/forums/topic/how-to-log-users-into-different-sites#post-555847

    https://premium.wpmudev.org/forums/topic/login-redirect-multisite#post-536580

    Hope this helps! :slight_smile:

    Kind Regards,
    Michael

  • George

    Great stuff! Do let us know if any further questions come up :slight_smile:

    Ok I have another question just to ask first if this is within the parameters of the help available here?

    So I hired someone from the Jobs & Pros section here and they did great but now making a few more modifications and its taking a while for them to get back to me. Maybe its the holidays but I work every day :slight_smile: So they made me a plug in that would create a registration form to create new user sites.

    There are just a few minor things that don't work yet but it is close. Like there is a field for "blog name" just like at edu blogs that I requested but it puts that data in the user nick name section of the profile instead of the "site name" in the general network settings.

    If I posted the plugin here would someone mind taking a look and just let me know if its a simple fix or if I need to hire a developer.

    thanks!!
    -George

  • Tyler Postle

    Hey George,

    Thanks for your reply!

    Our support includes anything WordPress related, so we can definitely take a look at this; however, as you mention, it may be something best suited for hiring a developer.

    We will let you know :slight_smile:

    Be sure to explain exactly what isn't working too. If there is quite a bit of custom code involved then that could help narrow down the search.

    You can create a new topic for this: https://premium.wpmudev.org/forums/#question

    Have a great rest of your weekend George!

    Cheers,
    Tyler

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.