WordPress.org

Ready to get started?Download WordPress

Forums

Site Redirection Help (2 posts)

  1. sicky_brazz
    Member
    Posted 3 months ago #

    Hi, I am trying to set my site up with a "None registered users are redirected to a landing page" scenario.

    I would like it so that all none registered users are redirected from all my pages (with the exceptions of only my registration, contact us, ToS & PP pages) to my landing page, NOT my home or login.php etc.

    So how can I go about doing this properly?

    I have tried using the following code but I just get a continuous redirect loop on normal WordPress pages and it seems to totally ignore my BBPress and BuddyPress pages, having them load no matter if the user is logged in or out.

    This is the code I was using:

    add_action('init','boot_non_users');
    function boot_non_users() {
      $world_pages = array(106,101,105,102,70,82,50,67,103,104);
    
      if (!in_array(get_the_ID(),$world_pages))
         if (!is_user_logged_in())
            wp_redirect('http://www.carfreaksunite.com/cfu-login');
    }

    P.S.
    I'm no coder and the above code was provided to me, so if anyone could provide help or guide me in the right direction of help (remembering I'm a noob at this), that would be awesome.

    Cheers.

  2. sicky_brazz
    Member
    Posted 3 months ago #

    ***UPDATE***
    I still need a hand but not as much as before...

    I have now put the following code into my functions.php file which allows me to essentially have 2 home pages, 1 for logged in users, 1 for logged out users.
    This is the code:

    /********** Multiple Static Home Pages **********/
    if( is_user_logged_in() ) {
        $page = get_page_by_title( 'Welcome!');
        update_option( 'page_on_front', $page->ID );
        update_option( 'show_on_front', 'page' );
    }
    else {
        $page = get_page_by_title( 'CarFreaksUnite' );
        update_option( 'page_on_front', $page->ID );
        update_option( 'show_on_front', 'page' );
    }

    However, I still can not get my head around, and could do with a solution to:
    >> Why I cant redirect my logged out users to my (now) home page without getting a continuous redirecting loop.
    >> Why BBPress and BuddyPress just wont follow any redirects.

Reply

You must log in to post.

About this Topic