Archived topic
Hooks
3 replies · Started by David Seibel on November 19, 2014
I'm pretty new to all this....
I added a video using hooks but just want to show it on the homepage. I put it in the content container and it (obviously) show up on all pages. My homepage is not a static page. I can see doing this on other pages if it is possible.
Since I'm just getting my feet wet with html, the more detail the better!
Thanks
Hi David,
To add things to specific pages, we'll need to use some PHP.
If your homepage is a blog, then we can do this:
<?php if ( is_home() ) : ?>
Your hook contents in here that should only show up on your blog
<?php endif; ?>
Then make sure you check the "Execute PHP" checkbox, and you should be good to go :)
Let me know if you need more detail.
Tom,
Thanks. That worked. Can I assume that to do this in any other page I can just replace the is_home() with is_pagename()?
Thanks again,
Dave
Almost, each page has what's called a "slug".
For example, the "slug" of the knowledgebase on this site is "knowledgebase", which is the name after the .com.
http://generatepress.com/knowledgebase/
So if I want to target something on that page, I would do this:
<?php if ( is_page( 'knowledgebase' ) ) : ?>
This will show up on the knowledgebase
<?php endif; ?>
Another example: http://generatepress.com/addons/
<?php if ( is_page( 'addons' ) ) : ?>
This will show up on the addons page
<?php endif; ?>
You can learn more about the WordPress conditionals here: http://codex.wordpress.org/Conditional_Tags