WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This code is fine but if I try to copy the last 3 lines and add a new custom page with a new custom header class, it doesn't work. I just want to add 2 new pages to my WP site with different headers from the front page and the rest of the site (which is set to use wrapper8 for the rest of the site pages which don't have specific headers). see: www.friendsofnamibianchildren.org Instead, very annoying, it applies wrapper8 to any new pages I add, thus applying the wrong template.

<?php if(is_front_page()) {?>
<div class="wrapper">
<?php } else { ?>
<div class="wrapper8">
<?php }?>
<?php if (is_page('About Us')) {?>
<div class="wrapper2">
<?php }?>
<?php if (is_page('Our Work')) {?>
<div class="wrapper3">
<?php }?>
<?php if (is_page('Get Involved')) {?>
<div class="wrapper4">
<?php }?>
<?php if (is_page('About Namibia')) {?>
<div class="wrapper5">
<?php }?>
<?php if (is_page('Donate')) {?>
<div class="wrapper6">
<?php }?>
<?php if (is_page('Photos')) {?>
<div class="wrapper7">
<?php }?>

If try to add these 3 lines below (basically a new Sitemap page with a 'wrapper9' header) then all the site templates get messed up.

<?php if (is_page('Sitemap')) {?>
<div class="wrapper9">
<?php }?>


share|improve this question
have you created the page with the title Sitemap? There should not be any spelling mistakes. – booota Dec 18 '11 at 1:20
the page file I was trying to add was called Sitemap.php and the reference to it was 'Sitemap' in the code. It was appearing in the template dropdown but instead of applying this new template's class of 'wrapper9', the statement would apply the 'wrapper8' tag instead. I double-checked references to make sure the spelling was correct but am not a developer so I could have missed something. thank you! – awesome Dec 18 '11 at 1:34
go to the admin, click all pages link under the pages section, check if you have a page named Sitemap or not. If not, then create one. This code should be working if there is a page with the title 'Sitemap' – booota Dec 18 '11 at 1:37
Thank you - the problem was that I had named the page 'Site Map' for the title, not 'Sitemap' as referenced in the template name and in the php code. Thanks so much. All fixed! – awesome Dec 18 '11 at 2:01

Your site seems to be not having a page named Sitemap. When I am saying this, it does mean to check your code, just check your site's dashboard. Under the Pages section, click All Pages link. This will show you all pages of your site. There you can see if you have a page with titled 'Sitemap' or not. If not, then create one and specify it's title as 'Sitemap' (without quotes). I am sure, you will get the results.

share|improve this answer
say thanks by selecting my answer and up-voting (if you like it) – booota Dec 18 '11 at 2:03
i will do this! thanks you solved my problem. – awesome Dec 19 '11 at 16:53
@awesome: my pleasure :P – booota Dec 20 '11 at 4:48

It's applying wrapper8 to any new page because it isn't the front page as per the first if/else statement. You'd need to join them all together into one string of if/else statements.

This code here cleans things up a bit (if it wasn't so late, I'd try to get it down to just one array):

    $pages = array('About Us','Our Work', 'Get Involved', 'About Namibia', 'Donate', 'Photos', 'Sitemap');
    $wrappers = array(
        'About Us'      =>  'wrapper2',
        'Our Work'      =>  'wrapper3',
        'Get Involved'  =>  'wrapper4',
        'About Namibia' =>  'wrapper5',
        'Donate'        =>  'wrapper6',
        'Photos'        =>  'wrapper7',
        'Sitemap'       =>  'wrapper9'
    if ( is_front_page() ) {
        $wrap = 'wrapper';
    } elseif (is_page($pages)) {
        $wrap = $wrappers[get_the_title()];
    } else {
        $wrap = 'wrapper8';
    <div class="<?php echo $wrap; ?>">
share|improve this answer
I will try this in the header.php file where the original code was, thank you so much!!! – awesome Dec 18 '11 at 1:32
totally bizarro your code kept everything the same, the wrapper 8 is still being applied - so this points to something else being the issue then perhaps? I cleared the cache too. ugh – awesome Dec 18 '11 at 1:38
This code only cleans things up and does not answer his query – booota Dec 18 '11 at 1:40

Sometimes with Wordpress I've had issues applying something through is_page(). The workaround I always do is to use the_permalink() in my IF conditions instead. Admittedly it's not the best thing if you want re-usable code, but on another project it's only another couple of minutes to adapt.

share|improve this answer
thanks good idea! – awesome Dec 19 '11 at 16:53

It looks like you're trying to create unique classes for styling on each page. Rather than going through all of this work (and having to update your theme for each new page which is unsustainable in the long run), look into the body_class() function. You use it like this:

<body <?php echo body_class(); ?>>

As the codex article shows, it gives you a ton of classes to work with. Better yet, if you need to add on more, you can just pass the function an argument which you might dynamically define beforehand:

<body <?php echo body_class( $my_custom_class ); ?>>
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.