I’m trying to add multiple page IDs into an if else statement. This is my code so far:
if ( is_page(ID) || is_page(ID) ) {
get_header('header_alt');
} else {
get_header();
}
I tried a few other solutions found on google, yet it always only works on the initial page after clearing the cache.
You can pass an array of IDs to is_page
instead of using multiple is_page
:
if( is_page( array( 11, 22, 33, 44 ) ) ) {
// Your code
}
Also, if you are using it in a loop, you should consider this note:
Due to certain global variables being overwritten during The Loop,
is_page() will not work. In order to call it after The Loop, you must
call wp_reset_query()
first.