Community Forums › Forums › Archived Forums › Design Tips and Tricks › Add hook only on home page
Tagged: hooks
- This topic has 5 replies, 4 voices, and was last updated 11 years, 11 months ago by
nutsandbolts.
-
AuthorPosts
-
April 29, 2014 at 2:06 pm #102984
TGScreative
MemberI 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.
http://nteu245.mystagingwebsite.com/<?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 } ?>April 29, 2014 at 5:38 pm #103010NewSeasonDesign
MemberI 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.)
April 29, 2014 at 5:40 pm #103012nutsandbolts
MemberTry 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. 😀
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/Developer, Nuts and Bolts Media
I provide development and training services for designers • Find me on Twitter and Google+April 30, 2014 at 1:41 pm #103102Brad Dalton
ParticipantHere'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.
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
May 1, 2014 at 10:00 am #103188TGScreative
MemberThank you. Works great NutsandBolts. Forgot about the static page being referenced by page ID
May 1, 2014 at 10:04 am #103189nutsandbolts
MemberNo 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/Developer, Nuts and Bolts Media
I provide development and training services for designers • Find me on Twitter and Google+ -
AuthorPosts
- The topic ‘Add hook only on home page’ is closed to new replies.