Skip to main content
Tweeted twitter.com/#!/StackWordPress/status/616866775343439872

Why isn't is_page doesn't workworking when I put it in the functions.php file?

Source Link
Wordpressor
  • 5.1k
  • 19
  • 70
  • 102

is_page doesn't work?

I have page called "Apple", the page's ID id 2533.

In page.php file I have line:

echo $bannerimg 

And this function in functions.php:

if ( is_page( '2533' ) ) {    
    // also tested with 'Apple'
    $bannerimg = 'apple.jpg';

} elseif ( is_page( 'test' ) ) {    
    $bannerimg = 'test.jpg';

} elseif ( is_page( 'admissions' ) ) { 
    $bannerimg = 'admissions.jpg';

} else { 
    $bannerimg = 'home.jpg';
}  

The point is the $bannerimg echoes "home.jpg" on every page, including Apple, test and admissions.

I've even checked all the IDs using the_ID & $page->ID. Nothing. So I guess there's something wrong with the code above?