Hiding certain content added with Simple Hooks

Community Forums Forums Design Tips and Tricks Hiding certain content added with Simple Hooks

This topic is: resolved

This topic contains 16 replies, has 3 voices, and was last updated by  braddalton 2 years, 3 months ago.

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
  • #46578


    I am using the decor theme and have installed the Simple Hooks plugin to add some Google Adsense ads in a few locations.  When using the landing page template (or one I could create if necessary), I want to be able to disable/hide/not show those ads.  What’s the best way to do that?  I’ve added content through simple hooks in “genesis_before”, “wp_footer”, and “genesis_after_content”.

    Basically on this page layout, I want the same thing as on my other pages EXCEPT the ads and the right sidebar.  I can control the second within the page author by choosing my desired layout.

    I’m not much of a coder, but I can modify examples.  Thus far I’ve played around with adding/modifying some of the “remove_action” items in the page template but to no avail.  I think this is probably because I either don’t have the right syntax or because these functions are controlled somewhere and I can’t find their root.



    Have you tried using conditionals? So you could use something like this in your hook:

    if ( is_home() ) {  my_code_and_function…();
    } else {

    If you’d like more case-by-case code help, you could include some code.



    Thanks for your response csbeck.  I initially thought a conditional would be a good solution, but I can’t wrap my head around how to write the statements.  I’m setting up pages for members only content and that content will have a different page template (without ads, for one).  Can I write a conditional that says if everything except page template X show this code and if this one particular page template don’t show it?



    Here’s an example of the code I’m trying to hide on the member page template:

    <div id=”skyscraper”>

    <script type=”text/javascript”>

    var width = window.innerWidth
    || document.documentElement.clientWidth
    || document.body.clientWidth;

    google_ad_client = “ca-pub-xxxxxxxxx”;

    if (width > 729) {
    // Load the 728×90 skyscraper Unit for wide screen
    google_ad_slot = “0154784691”;
    google_ad_width = 728;
    google_ad_height = 90;
    } else if ((width < 729) && (width > 479)) {
    // Load the 468×60 banner
    google_ad_slot = “1187018676”;
    google_ad_width = 468;
    google_ad_height = 60;
    } else {
    // For small screens, load the 320×50 small skyscraper
    google_ad_slot = “4140485076”;
    google_ad_width = 320;
    google_ad_height = 50;


    <script type=”text/javascript”

    • This reply was modified 2 years, 5 months ago by  myersbr2.
    • This reply was modified 2 years, 5 months ago by  myersbr2.


    Here are some other options.

    If you want to check if the user is logged in or not – http://codex.wordpress.org/Function_Reference/is_user_logged_in

    If you want to check on what ability the user has – http://codex.wordpress.org/Function_Reference/current_user_can

    Perhaps you can do this in sidebars? If you can then there’s a pretty great plugin that lets you show or hide a particular widget based on the page (you can either check to show or hide the sidebar on a particular page – on my project, we created a primary sidebar with all of the widgets in it and modified what widget was visible on a page by selecting it or hiding it by selecting it –  http://wordpress.org/plugins/display-widgets/.

    Alternatively, you could also write some custom conditional code to show or hide particular sidebar widgets and base it on which template is used.

    if ( is_page_template('about.php') ) {
    	// Returns true when 'about.php' is being used.
    } else {
    	// Returns false when 'about.php' is not being used.

    This is found in the WordPress Codex – http://codex.wordpress.org/Function_Reference/is_page_template

    To make your code work in one of these functions though, it would need to be turned into a PHP function or shortcode – http://codex.wordpress.org/Shortcode_API

    Another option might be to control it all with CSS. Depending on your child template, your BODY may have a class assigned to it when the user is logged in (logged-in). You could then create a CSS style with that class that points to that div and makes its DISPLAY: none. For instance:

    .logged-in #inner #content-sidebar-wrap #sidebar .widget { display: none; }

    Hopefully one of these will help.




    With our layout, sidebar options are out. :(

    For now I’m using your suggestion of hiding using CSS.  I’m not sure Google will be cool with that since I’m hiding adsense ads; I’ll have to look into that.  But for the meantime, it works.  Thanks!  If you (or anyone) has additional input, I’d prefer a way to make sure that when the page template is set as “member” these divs never load.  Here’s the code I ended up using:

    .logged-in #skyscraper,
    .logged-in #lijit,
    .logged-in #bottom-of-post-ad,
    .logged-in .footer-widget-email-signup {
    display: none;



    This might help. If i clearly understand what you wanted, i could write the code for you.

    This code works for logged in and logged out users.



    Brad that is VERY generous!  I’ll take it…or any suggestions you have.  Originally I didn’t think it would matter if someone were logged in or not, as I’m using S2 member plugin to drive all the access restrictions.  Instead, I thought it best to set a page template “member” for all members-only content when someone is logged in and so when the page template is “member”, that’s when they’d see a change in look/feel.  If looking at whether or not someone is logged in is a better approach, I’m okay with it.  Basically the difference in the member view vs. the non-member is that there are no ad divs on a member view and no sidebar.  This would be fine on any/all pages for members or just those restricted as members-only content.  I just want someone who is a member, when accessing member content, to definitely see a different view.  Clear as mud?

    Here’s what I’m looking to change.  

    1. When a user is on the page_member.php page template (or when they are logged in as a member, if that’s a better option), I want the following divs to not load:

    #skyscraper, #lijit, #bottom-of-post-ad, .footer-widget-email-signup

    Right now I’ve done this through CSS, but I’ve learned Google won’t like that for adsense AND it will skew clickthrough numbers.  I added the first three divs using the Simple Hooks plugin, and placed them in the following locations (in order, based on the divs above):

    genesis_before, genesis_after_content, genesis_after_post_content

    The .footer-widget-email-signup is a widget called (in the dashboard) footer 2.  I’m not sure what it is in php.

    2. I would like to default to the full content width design, which right now is defined as:

    <body class=”page page-id-33805 page-template page-template-page_member-php full-width-content”>

    example page: http://www.stacymakescents.com/membership-restricted-page-test

    vs. with a standard page, the body is set up as:

    <body class=”page page-id-7434 page-template-default content-sidebar”>

    example page: http://www.stacymakescents.com/aboutme

    Of course the page ID is irrelevant, but the rest is dictated by the page template and the selection I make within the page editor to choose the full-width-content.



    Thanks for clarifying. If i can contribute a better solution, i will.

    Not difficult to integrate what Chris offers with the page conditional is_page_template and the is_user_logged_in

    I’m going to do some testing locally on this because i love conditionals and s2 member is also my favorite membership plugin.

    Not sure how to stop the divs loading but maybe you don’t need to do that if you use a custom page template. That would make it very easy with conditionals.

    Be very interested to see your final code.



    Are these in widgets?

    #skyscraper, #lijit, #bottom-of-post-ad, .footer-widget-email-signup

    If so, you could easily add a conditional for logged in and logged out users/members to each widget using the Widget Logic plugin.



    Only the last one is in a widget. The rest are in hooks I added through the Genesis Simple Hooks Plugin. The divs you reference are in the following hooks: genesis_before, genesis_after_content, genesis_after_post_content



    Be really easy to convert that PHP code in Simple Hooks to custom functions which include widgets. Then you can add the conditional to the code or use the Widget Logic plugin with conditional in any widget.

    I gather you have functions for adding text/HTML in specific hook positions using the plugin?

    I would also update to Genesis 2.0 and add HTML 5 support to your child themes at the same time and use the new hooks.

    Simple hooks will be updated with the new hooks the same day Genesis 2.0 is released within a week of WordPress 3.6 being released.

    Here’s an example using the new hooks

    Change the conditionals or remove them and use the Widget Logic plugin.

    Change the hooks to anything you like.

    This code uses existing CSS which styles the footer so no CSS needed. You can change the Div class to match the widget i.d if you don’t want any styling or different styling than your footer.



    I’ll play with this and see if I can come up with something. Thanks for the input! Ideally, I just want some of the hooks to “disappear” (content within them, at least) when the user is logged in. As a non-programmer, this one has been giving me fits.



    Paste 1 of the code snippets used in 1 hook field in a new Github Gist or use Pastebin and leave a link here and i’ll give you 1 working example.



    Here’s the pastebin URL: http://pastebin.com/CtR4gVYy

    THANK YOU for that. I can usually follow examples. ;0)

Viewing 15 posts - 1 through 15 (of 17 total)

You must be logged in to reply to this topic.