Community Forums › Forums › Archived Forums › Design Tips and Tricks › Help with conditionals for action hooks
- This topic has 9 replies, 3 voices, and was last updated 9 years, 11 months ago by
sethbahookey.
-
AuthorPosts
-
March 8, 2015 at 3:04 pm #143697
sethbahookey
MemberHello! I am trying to add a snippet of code to the bottom of my pages in my website. However, I only want it to show up on some pages and not on others. I'm trying to wrap a conditional around an action hook to let it know whether it needs to display or not. For some reason it is working backwards... See below.
if( is_page() ) {
add_action('genesis_entry_footer', 'hello_world');
function hello_world() {
echo "hello world";
}
}This should display a small hello world at the bottom of the entry section of this page, but it shows nothing!
if( !is_page() ) {
add_action('genesis_entry_footer', 'hello_world');
function hello_world() {
echo "hello world";
}
}When I turn it to "is not page" as the conditional then it pops up. So what the heck is going on here? My page is really a post? when I try is_single() that doesn't work either. Please help!
thecompressioncloset.com
http://thecompressioncloset.comMarch 8, 2015 at 4:03 pm #143705Brad Dalton
ParticipantMarch 8, 2015 at 4:10 pm #143706sethbahookey
MemberThanks for the response! Could you provide an example please? This is how I am understanding you...
add_action(‘genesis_entry_footer’, ‘hello_world’); function hello_world() { if( is_page() ) { echo “hello world”; } }
The thing is I want to either add or remove an action hook based on whether I'm on a certain section of my site.
So something like:
if( !is_page('contact-us') || !is_page('about-us') ) { add_action('genesis_entry_footer', 'wpmem_inc_sidebar'); }
wpmem_inc_sidebar is what I'm actually trying to insert into the site. The challenge is that it is not recognizing those conditionals :/
March 8, 2015 at 4:16 pm #143710sethbahookey
MemberP.S. - I just put this in the site so you can see what I mean about it being on every page...
thecompressioncloset.com
if( !is_page('contact-us') || !is_page('about-us') ) { add_action('genesis_entry_footer', 'wpmem_inc_sidebar'); }
March 8, 2015 at 4:17 pm #143712Brad Dalton
ParticipantYour first snippet looks o.k
As far as support for adding a plugins functionality, the best people to ask are the plugin Developers.
Hard to provide support for 35,000+ plugins.
March 8, 2015 at 4:58 pm #143720sethbahookey
MemberOk, either way, the conditionals aren't working regardless of plugin. So I'm wondering what went wrong there.
March 8, 2015 at 11:10 pm #143746coralseait
MemberMarch 8, 2015 at 11:23 pm #143747Brad Dalton
ParticipantYour first snippet looks fine to me. Where did you put the code because it should be in functions.php
March 10, 2015 at 5:25 am #143894sethbahookey
MemberWell I did a search through the whole WP folder and it looks like that 'genesis_entry footer is sprinkled throughout the post.php page.
March 10, 2015 at 5:26 am #143895sethbahookey
MemberYes I did place it within functions.php at the bottom of that page. Is there a way to do a check on the page itself to determine what it's page id is? I mean I've switched the permalinks back to default to get the page id that way, but still nothing!
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.