Add hook only on home page

Community Forums Forums Design Tips and Tricks Add hook only on home page

This topic is: resolved

Tagged: 

This topic contains 5 replies, has 4 voices, and was last updated by  nutsandbolts 5 months, 3 weeks ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #102984

    TGScreative
    Member
    Post count: 19

    I added an image underneath the navigation bar in the basic Genesis child theme.
    I used the hook “genesis_after_header”
    The image looks great but I only wanted it on the home page. Ay ideas how to use a hook only on one page on the site?

    I tried using a little PHP but not sure exactly how it works. This is the code I used.

    <?php if(is_home) { ?>
    <div style="background: #eeeeee; text-align: center;"><img src="/wp-content/uploads/2014/04/collage.jpg" width="1160" height="205"></div>
    <?php endif; ?>
    <?php } ?>
    http://nteu245.mystagingwebsite.com/
    #103010

    NewSeasonDesign
    Participant
    Post count: 35

    I would do this:

    <?php if (is_home()) { ?><div style="background: #eeeeee; text-align: center;"><img src="/wp-content/uploads/2014/04/collage.jpg" width="1160" height="205"></div>
    <?php } ?>
    

    If is_home doesn’t work, try is_front_page.

    Then make sure that you check the box for php under the hook. (Not that I’ve ever forgotten do that… ahem.)

    #103012

    nutsandbolts
    Moderator
    Post count: 3137

    Try this:

    <?php if (is_home()) { ?><div style="background: #eeeeee; text-align: center;"><img src="/wp-content/uploads/2014/04/collage.jpg" width="1160" height="205"></div>
    <?php } ?>
    

    Edit: and I see Jen was ahead of me. :D

    and be sure to check the box to execute PHP on the hook ( I’m assuming you’re using Simple Hooks?).

    If your homepage isn’t set to show posts in Settings > Reading and is set to a static page instead, you’ll want to do this:

    <?php if (is_page(PAGE ID GOES HERE)) { ?><div style="background: #eeeeee; text-align: center;"><img src="/wp-content/uploads/2014/04/collage.jpg" width="1160" height="205"></div>
    <?php } ?>
    

    You can find the page ID by hovering over the Edit link for that particular page.


    Andrea Whitmer, Owner, Nuts and Bolts Media
    I provide dev and training services for web designers • Find me on Twitter and Google+

    • This reply was modified 5 months, 3 weeks ago by  nutsandbolts.
    • This reply was modified 5 months, 3 weeks ago by  nutsandbolts.
    #103102

    braddalton
    Participant
    Post count: 10157

    Here’s another way to add an image after the header on the front page.

    Simply add your image to your child themes images folder and change the image file name in the code to match your image.

    http://wpsites.net/web-design/add-image-after-front-page-primary-nav-menu-apparition-theme/

    Also best practice to keep all your CSS in your child themes style sheet rather than use inline CSS


    #103188

    TGScreative
    Member
    Post count: 19

    Thank you. Works great NutsandBolts. Forgot about the static page being referenced by page ID

    #103189

    nutsandbolts
    Moderator
    Post count: 3137

    No problem! I’ve marked this topic as resolved for now, but feel free to open a new topic if you run into issues. :)


    Andrea Whitmer, Owner, Nuts and Bolts Media
    I provide dev and training services for web designers • Find me on Twitter and Google+

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Add hook only on home page’ is closed to new replies.