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.
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
}
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!';
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With