Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress - Check if user is logged in

Tags:

php

wordpress

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 the function is_logged_in doesn't seem to work.

I want to place a condition in my header.php file to check if the user has logged in (and then display the navigation).

Any advice would be helpful.

like image 875
user1411837 Avatar asked Nov 13 '13 06:11

user1411837


2 Answers

Use the is_user_logged_in function:

if ( is_user_logged_in() ) {
   // your code for logged in user 
} else {
   // your code for logged out user 
}
like image 103
Bhumi Shah Avatar answered Nov 10 '22 12:11

Bhumi Shah


Example: Display different output depending on whether the user is logged in or not.

<?php

if ( is_user_logged_in() ) {
    echo 'Welcome, registered user!';
} else {
    echo 'Welcome, visitor!';
}

?>
like image 6
Abdo-Host Avatar answered Nov 10 '22 14:11

Abdo-Host