WordPress - Check if user is logged in

后端 未结 6 1612
逝去的感伤
逝去的感伤 2020-12-08 19:35

I am fairly new to WordPress. On my homepage I have a navigation bar which I only want to show to people who are logged in as users.

In my header.php th

6条回答
  •  悲&欢浪女
    2020-12-08 20:26

    Try following code that worked fine for me

    global $current_user;
    get_currentuserinfo();
    

    Then, use following code to check whether user has logged in or not.

    if ($current_user->ID == '') { 
        //show nothing to user
    }
    else { 
        //write code to show menu here
    }
    

提交回复
热议问题