• Resolved sonyrhd

    (@sonyrhd)


    Hello, I would like to be able to set up a private website. I want the user to be redirected to a custom URL (which contains a login and registration form) instead of the typical “wp-admin” page. I have tried various things, including the “redirect” plugin, but the “private site” mode takes priority over this redirection.

    Do you have a way to redirect to a custom URL when the user is not logged in?

Viewing 1 replies (of 1 total)
  • Plugin Author Caseproof

    (@caseproof)

    Hi @sonyrhd

    You could try to disable Private Site and then add this code snippet at the end of your theme’s functions.php file:

    add_action( 'template_redirect', function() {
      $user = wp_get_current_user();
      if ( !is_page( 'login' ) && ( ! is_user_logged_in() || ( ! empty($user) && in_array( 'administrator', (array) $user->roles ) ) ) ) {
        $redirect = 'https://your-domain.com/login';
        wp_redirect( $redirect );
        exit;
      }
    } );

    The login page would be the page where you can add login form shortcode.

    I hope that helps.

Viewing 1 replies (of 1 total)
  • The topic ‘Private site and custom URL’ is closed to new replies.