• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Hiding certain content added with Simple Hooks

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

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

This topic is: resolved

Tagged: decor, hide, plugin, remove_action, Simple Hooks

  • This topic has 16 replies, 3 voices, and was last updated 10 years, 1 month ago by Brad Dalton.
Viewing 17 posts - 1 through 17 (of 17 total)
  • Author
    Posts
  • June 18, 2013 at 11:42 am #46578
    myersbr2
    Member

    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.

    http://www.stacymakescents.com
    June 18, 2013 at 2:22 pm #46614
    csbeck
    Member

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

    if ( is_home() ) {  my_code_and_function...();
    } else {
    my_other_code_and_function...();
    }

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

    June 19, 2013 at 6:46 am #46717
    myersbr2
    Member

    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?

    June 19, 2013 at 7:21 am #46726
    myersbr2
    Member

    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 728x90 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 468x60 banner
    google_ad_slot = "1187018676";
    google_ad_width = 468;
    google_ad_height = 60;
    } else {
    // For small screens, load the 320x50 small skyscraper
    google_ad_slot = "4140485076";
    google_ad_width = 320;
    google_ad_height = 50;
    }

    </script>

    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    </div>

    June 19, 2013 at 8:49 am #46741
    csbeck
    Member

    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.

    Chris

    June 19, 2013 at 2:44 pm #46805
    myersbr2
    Member

    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;
    }

    June 19, 2013 at 5:53 pm #46825
    Brad Dalton
    Participant

    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.


    Tutorials for StudioPress Themes & WooCommerce.

    June 20, 2013 at 8:12 am #46881
    myersbr2
    Member

    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.

    June 20, 2013 at 8:30 am #46883
    Brad Dalton
    Participant

    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.


    Tutorials for StudioPress Themes & WooCommerce.

    June 20, 2013 at 2:26 pm #46924
    Brad Dalton
    Participant

    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.


    Tutorials for StudioPress Themes & WooCommerce.

    June 20, 2013 at 2:32 pm #46925
    myersbr2
    Member

    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

    June 20, 2013 at 2:48 pm #46930
    Brad Dalton
    Participant

    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.

    Styling:
    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.


    Tutorials for StudioPress Themes & WooCommerce.

    June 20, 2013 at 2:59 pm #46931
    myersbr2
    Member

    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.

    June 20, 2013 at 3:11 pm #46935
    Brad Dalton
    Participant

    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.


    Tutorials for StudioPress Themes & WooCommerce.

    June 20, 2013 at 6:44 pm #46979
    myersbr2
    Member

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

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

    August 14, 2013 at 8:49 am #56306
    myersbr2
    Member

    I was able to get this working and it has remained functional for a couple of weeks now. Thanks to braddalton and others who gave me the input to make it happen!

    Final code to make this work was (inserted in simple hooks, this code was specifically in genesis_Before:

    <?php
    if ( !is_user_logged_in() ) { ?>

    <div id="skyscraper">
    DIV CONTENT HERE
    </div>

    <?php }
    ?>

    It turned out that having someone logged in was the best approach to consider because only those users who register on the site (paid members) would be the only ones logging in. We don't have a "free" membership level so this solved it nicely.

    August 14, 2013 at 9:12 am #56313
    Brad Dalton
    Participant

    No worries. Good solution.


    Tutorials for StudioPress Themes & WooCommerce.

  • Author
    Posts
Viewing 17 posts - 1 through 17 (of 17 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble