Support » Fixing WordPress » Only Showing Elements on Homepage & Certain Pages

  • Resolved ianbee

    (@ianbee)


    Hi, I’m trying to get certain elements within my wordpress blog to only show on the front page, and other pages. I can successfully get items to only show on homepage by doing the following:

    <?php if( is_front_page() ) : ?>
    content...
    <?php endif;?>

    I can also show elements on just an array of pages by doing the following:

    <?php if(is_page(array(42,'bio','services'))) { ?>
    content...
    <?php } ?>

    I’m unsure how to show elements on both the front page and certain pages.. I tried the following but nothing worked…

    <?php if(is_page(array(42,'bio','services'))) { ?>
    <?php if( is_front_page() ) : ?>
    content...
    <?php } ?>

    I thought it could have been the “<?php } ?>” so I tried doing “<?php } ?><?php endif;?>” and also just “<?php endif;?>”

    Again, nothing worked.

    So how do I make certain elements only appear on the front page AND certain pages?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Peter_L

    (@peter_l)

    Use boolean operators:
    or -> ||
    and -> &&

    In your case, you need the or operator. You want to do something if it’s a certain page OR the front page. Looks like this:

    <?php
    if( is_front_page() || is_page(array(1,2,3)) ){
         //do something
    }
    ?>

    ianbee

    (@ianbee)

    @peter_l I tweeked the code a bit and it worked! thanks so much man! 😀

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Only Showing Elements on Homepage & Certain Pages’ is closed to new replies.