Php function with 2 "if"s

I added a function to my website that displays a custom nav for logged in members only. I need to add another condition (that it will not show on certain pages even if someone is logged in). Anyone know how to do this? I can go according to the page IDs.

This is the code I have SO FAR:


function add_notification_header() { 
 
if (is_user_logged_in()) {

 

nav content added here

     }
}

add_action( 'wp_head', 'add_notification_header' );

In other words I need to add another “if” , aka if page ID is not a and y and z… - anyone know how to do this? Can I have 2 “if” in one function or is there a different way to write it once there are 2 conditions?

@peninah_adler

Thanks!

I was actually just working on a similar idea for someone!

I think this might be able to work for you.
Try replacing the IF statement with this one and where it says page-id replace it with the page id numbers.
This should display the function if the user is logged in but is not on any of these pages…

Hope it helps!

if (is_user_logged_in() && !is_page(page-id) && !is_page(page-id)) {

}

Thank you so much! It worked! However I then realized I need the opposite: to remove the preexisting header when the user is logged in, to keep the custom nav. Any idea how to do that?

I would start with…
if (is_user_logged_in()
I would then remove/menion the class of the existing header and do “display:none;” for it…something like that :slight_smile:

I’m not sure I’m following, but if you’re just going to “display:none,” as opposed to replacing the nav entirely, you could utilize the .logged-in class and maybe use a :not class, ie,

body:not(.logged-in) { …etc

@peninah_adler Thank you! You saved the day again!