skip to Main Content

I have the code below in my page.php template but the div isn’t showing up on the woocommerce pages. Rather, nothing shows up. What is wrong with the code?

<?php if ( is_page('woocommerce') ): ?>

  <div id="banner">
    <h2>New shop is open!</h2>
  </div>

<?php endif; ?>

3

Answers


  1. Use like this.

    <?php  
        global $post;
    
         if( $post->ID == 346) { ?>
    
              <!-- do your stuff here -->
    
        <?php } ?>
    
    Login or Signup to reply.
  2. This function is_page in wordpress is a function to check if a page exist with id, title, slug, array. You can read more about is_page() function in the wordpress documentation

    With your code, you are checking a page with slug or title = “woocommerce” exists or not. Were do you check if this page exists in your wordpress?

    Login or Signup to reply.
  3. Maybe there is another template, like page-woocommerce.php kicking in before page.php. See: https://developer.wordpress.org/themes/basics/template-files/.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search