• Hi,

    I’m trying to build a function which redirect not logged in users:
    If the user is not logged in and if the page he/she is trying to reach is not mydomain.com then he/she goes to mydomain/welcome

    Sorry if this is super basic but I am more than a dummy with php…

    Thanks in advance for your help!
    T

Viewing 2 replies - 1 through 2 (of 2 total)
  • C W (VYSO)

    (@cyril-washbrook)

    Something like this will probably work, assuming I’ve understood your question:

    <?php
    if( !is_user_logged_in() && !is_front_page() ) :
       wp_redirect( home_url( $path = '/welcome' ) );
    endif;
    ?>

    If the user is not logged in, and if the current page displayed is not the front page, the user is redirected to {home url}/welcome.

    Thread Starter ThomasVig

    (@thomasvig)

    Hi Cyril,

    Thanks for your answer! Unfortunately, it does not work. Even if the user goes on the front page (www.mydomain.com) it gets redirected to https://www.mydomain.com/welcome.

    The next issue is that it does not open the page https://www.mydomain.com/welcome as there are too many redirects, any idea where it could come from?

    Thanks again for your help,
    T

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Redirect’ is closed to new replies.