Community Forums › Forums › Archived Forums › Design Tips and Tricks › Hooks
Tagged: conditional tags, exclude pages
- This topic has 6 replies, 2 voices, and was last updated 7 years, 3 months ago by Brad Dalton.
-
AuthorPosts
-
December 21, 2016 at 8:45 pm #197974hillyutMember
Hi, I am trying to suppress a simple hook on a few of my lesson pages, like this one:
http://www.pullingcurls.com/course/online-prenatal-class-couples (they use LIfterLMS)
I don't like having my header "ads" up there as they are paid classes.
I did get rid of the header and sidebar with this code:
.single-course .site-container .nav-primary,
.single-course .site-container .nav-secondary,
.single-course .site-container .site-header,
.single-lesson .site-container .nav-primary,
.single-lesson .site-container .nav-secondary,
.single-lesson .site-container .site-header {
display: none;
}On the hook I was trying to use this (using the conditional tags that Lifter gave me):
<?php
if (!is_lesson() ) || !is_course() || !is_archive() )
{ ?>//insert code for ad here
<?php }
?>But when I execute php on that simple hook it throws and error and the rest of my site won't load.
My host said that something is wrong with that coding.Is there ANY way to do it? Is there a way to add one of the hooks to that top code that says display none?
Thanks!
http://www.pullingcurls.com/course/online-prenatal-class-couples
HilaryDecember 21, 2016 at 9:04 pm #197975Brad DaltonParticipantI suggest you use PHP code in your functions file to load the advert and include conditional tags with the NOT operator to exclude pages.
add_action('genesis_before_loop', 'your_function'); function your_function() { if ( !is_lesson() ) || !is_course() || !is_archive() ) { echo '<div class="advert"> Add Your Text or HTML Here</div>'; } }
You can swap out genesis_before_loop with any hook
December 24, 2016 at 7:18 am #198071hillyutMemberBrad, thank you so much! I'm going to try this right after work!
December 26, 2016 at 7:54 am #198214hillyutMemberOk, I tried it -- but it throws this error: [26-Dec-2016 13:49:09 UTC] PHP Parse error: syntax error, unexpected '||' (T_BOOLEAN_OR) in /home/nginx/domains/pullingcurls.com/public/wp-content/themes/lifestyle-pro/functions.php on line 124
Any chance I'm putting it in the wrong spot? I'm always nervous in the functions file....
December 26, 2016 at 8:09 am #198216Brad DaltonParticipantTry this:
add_action('genesis_before_loop', 'your_function'); function your_function() { if ( ! is_lesson() || ! is_course() || ! is_archive() ) { echo '<div class="advert">Add Your Text or HTML Here</div>'; } }
December 29, 2016 at 8:17 am #198412hillyutMemberOk, that didn't throw an error. BUT, it also didn't work.
Is there a way to add it to the css file like above?.single-course .site-container .nav-primary,
.single-course .site-container .nav-secondary,
.single-course .site-container .site-header,
.single-lesson .site-container .nav-primary,
.single-lesson .site-container .nav-secondary,
.single-lesson .site-container .site-header {
display: none;
}December 29, 2016 at 8:34 am #198414Brad DaltonParticipantThe code works however it uses the conditionals you supplied ( which come from Lifter ) so you will need to check them. Its example code you can modify.
Here's the WordPress conditionals you can swap out in the code.
Or
You can use CSS to hide the ads using the body classes which you can inspect in the HTML source code.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.