PHP HomePage

Discussion in 'WordPress' started by Earl Sargent, Feb 7, 2014.

  1. #1
    Hey guys, I need to write a PHP function that determintes wether or not a user is logged into Wordpress. If they are, I would like them to be directed to the content page. If they are not, I would like them to be directed to the page with the front-end login. How would I write that and where would I put it?
     
    Earl Sargent, Feb 7, 2014 IP
  2. AgileRack

    AgileRack Greenhorn

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    13
    #2
    Have you checked out this redirect script: http://stackoverflow.com/questions/11238375/wordpress-redirect-user-if-not-logged-in

    There are also some plugins that can automate this without programming.
     
    AgileRack, Feb 7, 2014 IP
  3. Earl Sargent

    Earl Sargent Greenhorn

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    I kinda wanted to do it without a plugin to learn the code a bit better, but this is perfect! Thanks :)
     
    Earl Sargent, Feb 7, 2014 IP
  4. RobinInTexas

    RobinInTexas Active Member

    Messages:
    217
    Likes Received:
    14
    Best Answers:
    2
    Trophy Points:
    65
    #4
    RobinInTexas, Feb 9, 2014 IP
  5. themes4all

    themes4all Well-Known Member

    Messages:
    662
    Likes Received:
    47
    Best Answers:
    6
    Trophy Points:
    100
    #5
    in fact you can use 2 functions at one :
    
    <?php if (!is_user_logged_in()) { auth_redirect(); } ?>
    
    Code (markup):
    learn more about auth_redirect : http://codex.wordpress.org/Function_Reference/auth_redirect

    in fact with this function, we check if user is logged in, if yes so nothing to do... once logged in, he/she will be redirected to the last page they was in...

    Goodluck
     
    themes4all, Feb 11, 2014 IP
    ryan_uk likes this.