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

I am creating a wordpress theme from scratch. I have created a seperate page to show the Blog Posts. In my all pages I want to show a div class named as shopping-cart, but I want to hide it from page id=42 (wordpress-naked BlogPage) and single.php.

I have coded in my header.php like below

<?php if( is_page() ) { ?>

            <div  class="shopping-cart pull-right info" >Shopping Cart : <span class="simpleCart_quantity"></span> items - <span class="simpleCart_total"></span>
   <span class="ViewCART" onClick="myFunction()">View Cart</span>

 <div class="down">
       <div class="triangle">&#x25B2;</div>

               <div ><h2>Your Cart Details</h2></div>
            <div class="cartData clearfix"><div class="left"><strong>Items: </strong><span class="simpleCart_quantity"></span></div>

                        <div class="right"><strong>Total: </strong><span class="simpleCart_total"></span></div></div>

            <div class="grandTotal"><strong>Grand Total:<div class="simpleCart_grandTotal"></div></strong></div>

           <div class="centercart"><a href="javascript:;" class="simpleCart_checkout" ><img src="<?php bloginfo('stylesheet_directory'); ?>/images/paypal.png"/></a></div>

            <div class="centercart"><a href="javascript:;" class="simpleCart_checkout" ><img src="<?php bloginfo('stylesheet_directory'); ?>/images/google-chk.png"/></a></div>
           <div class="centercart"><a href="javascript:;" class="simpleCart_empty"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/clear.png"/></a></div>
             <div class="closecart"><span onClick="myFunction2()">Close</span></div>

<?php } ?>

It is working fine. The particular div shopping-cart is showing in the pages and hiding from the single.php. But the problem is that I have coded Blog as a separate blog.php which is a page named as wordpress-naked BlogPage and having it's page id =42. So now I want to hide the shopping-cart div in the wordpress-naked BlogPage and single.php together.

I got stuck in this. Can anyone please to sort it out. Thanks in advance.

share|improve this question
up vote 0 down vote accepted

Just change this:

<?php if( is_page() ) { ?>


<?php if( is_page() && !is_page(42) ) { ?>

You can also try to use is_home() and is_front_page(). These 2 will be even better, since they are more universal (not based on pageId). If you change the page that is your home/front page, this will still work.

share|improve this answer
Thanks Drozdz. I was really stuck off in this. Thanks a lot again for your effort.. It worked... – amitabhaghosh197 Aug 3 '13 at 9:14

$page = get_query_var('page_id');

if($page == 42 || is_single() ) {

$class= 'shopping-yourname';

} else {

$class = 'shopping-cart';


share|improve this answer
Well, I don't think you should do this like that. You should use is_page and is_single functions... – Krzysiek Dróżdż Aug 2 '13 at 14:11
Yes, and that's why is_page function have parameter ;) – Krzysiek Dróżdż Aug 2 '13 at 14:19
The other problem with your answer is that all it does, is setting some class variable. So it isn't an answer at all, I guess. – Krzysiek Dróżdż Aug 2 '13 at 14:21

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.