• 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

Conditional Action Hook Question

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 › Conditional Action Hook Question

This topic is: resolved
  • This topic has 5 replies, 2 voices, and was last updated 10 years, 11 months ago by nomis.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • May 23, 2015 at 11:11 am #153423
    nomis
    Member

    Hi again,

    I’m working with a Genesis theme which uses Action Hooks to add and remove widget areas. My site divides posts into two main categories. The two blogs are completely separate from each other and are accessed by separate main menu items. Clicking on “Blog” takes you to a normal blog, and clicking on “Tutorials” takes you to a portfolio template page which leads through to completely separate tutorial posts.

    So far I have registered two widget areas to the ‘genesis_after_header' hook. One widget appears on the Blog Page, and the other appears on the Tutorials Page. They both contain custom menus. This means that when you're in the Blog, you can filter the blog categories, and when you’re in Tutorial you can filter the tutorial categories. The Tutorial Submenu filters by removing categories from the portfolio page. This is the code that I’m using, and it works just fine:

    // **************************** BLOG SUBMENU WIDGET ****************************
    //* rise - Register blog-submenu widget area
    genesis_register_sidebar( array(
    	'id'            => 'blog-submenu',
    	'name'          => __( 'Blog Submenu', 'epik' ),
    	'description'   => __( 'Place submenu for Blog Page here', 'epik' ),
    ) );
    
    //* rise - Hook blog-submenu widget area after header
    add_action( 'genesis_after_header', 'add_blog_submenu' );
    function add_blog_submenu() {
    	if  (is_singular(post) && is_category('Blog') || is_category('Blog_Web') || is_category('Blog_Photos') || is_category('Blog_General') || is_page('Blog'))
    		genesis_widget_area ('blog-submenu', array (
    		'before' => '<div class="wrap"><div class="blog-submenu widget-area">',
    		'after'  => '</div></div>',
    		)
    	);
    }
    
    // ***************************** TUTS SUBMENU WIDGET ***************************
    //* rise - Register tuts-submenu widget area
    genesis_register_sidebar( array(
    	'id'            => 'tuts-submenu',
    	'name'          => __( 'Tuts Submenu', 'epik' ),
    	'description'   => __( 'Place submenu for Tuts Page here', 'epik' ),
    ) );
    
    //* rise - Hook tuts-submenu widget area after header
    add_action( 'genesis_after_header', 'add_tuts_submenu' );
    function add_tuts_submenu() {
    	if (is_page('Illustrator Tutorials') || is_page('Sublime Text Tutorials') ||  is_page('Photoshop Tutorials') || is_page('Tutorials') || is_category('Tuts_PS') || is_category('Tuts_Ill') || is_category('Tuts_ST'))
    		genesis_widget_area ('tuts-submenu', array (
    		'before' => '<div class="wrap"><div class="tuts-submenu widget-area">',
    		'after'  => '</div></div>',
    		)
    	);
    }
    

    However, the filter menus (Submenus) were not showing up on single posts. So I added (is_singular('post') to the Blog Submenu code:

    //* rise - Hook blog-submenu widget area after header
    add_action( 'genesis_after_header', 'add_blog_submenu' );
    function add_blog_submenu() {
    	if  (is_singular(post) || is_category('blog_web') || is_category('blog_photos') || is_category('blog_general') || is_page('blog'))
    		genesis_widget_area ('blog-submenu', array (
    		'before' => '<div class="wrap"><div class="blog-submenu widget-area">',
    		'after'  => '</div></div>',
    		)
    	);
    }
    

    This worked fine, but the blog-submenu was now also showing on the Tutorial single posts. So I added (is_singular(post) && is_category(‘blog'). My thought was that this would only add the blog-submenu to single posts that also had the Blog category attached to them.

    //* rise - Hook blog-submenu widget area after header
    add_action( 'genesis_after_header', 'add_blog_submenu' );
    function add_blog_submenu() {
    	if  (is_singular(post) && is_category('blog') || is_category('blog_web') || is_category('blog_photos') || is_category('blog_general') || is_page('blog'))
    		genesis_widget_area ('blog-submenu', array (
    		'before' => '<div class="wrap"><div class="blog-submenu widget-area">',
    		'after'  => '</div></div>',
    		)
    	);
    }

    But this made the blog-submenu disappear from ALL single posts. So I added this (is_singular(post) && !is_category('Tutorials'). My thought was that this would only add the blog-submenu to single posts that did NOT have the Tutorials category attached to them.

    //* rise - Hook blog-submenu widget area after header
    add_action( 'genesis_after_header', 'add_blog_submenu' );
    function add_blog_submenu() {
    	if  (is_singular(post) && !is_category('Tutorials') || is_category('Blog_Web') || is_category('Blog_Photos') || is_category('Blog_General') || is_page('Blog'))
    		genesis_widget_area ('blog-submenu', array (
    		'before' => '<div class="wrap"><div class="blog-submenu widget-area">',
    		'after'  => '</div></div>',
    		)
    	);
    }
    

    This did not remove the blog-submenu from single posts that had the Tutorials category attached.

    So basically, I want to add the blog-submenu widget to single posts that have the Blog category, but not the Tutorials category. Can anyone help?

    May 23, 2015 at 1:11 pm #153430
    Graham
    Member

    I would need to double check your logic, so bear with me, yet for now ..

    is_singular() parameter is either string || array

    is_singular( post )

    should be

    is_singular( 'post' )


    My JustGiving page: https://www.justgiving.com/helping-graham-give

    May 23, 2015 at 2:04 pm #153433
    Graham
    Member

    is_category() checks if a category archive page is being displayed.
    To test if a post is in a category use in_category()

    So basically, I want to add the blog-submenu widget to single posts that have the Blog category, but not the Tutorials category. Can anyone help?

    if( is_singular('post') && in_category('Blog') {
        // show blog-submenu
    }

    My JustGiving page: https://www.justgiving.com/helping-graham-give

    May 23, 2015 at 3:02 pm #153437
    nomis
    Member

    Superb !!!
    This solved my problem perfectly - and I learned something 🙂
    Thanks soooooooooo much Graham.

    si

    May 23, 2015 at 3:20 pm #153438
    Graham
    Member

    Glad it helped 🙂

    I can't edit my post, so I've corrected my typo from above here (missing closing bracket ) for future copy pasta.

    if( is_singular('post') && in_category('Blog')) {
        // show blog-submenu
    }

    My JustGiving page: https://www.justgiving.com/helping-graham-give

    May 24, 2015 at 5:04 am #153462
    nomis
    Member

    Have attempted to copy pasta.
    Tagliatelle now jammed in photocopier.
    Is copying pasta essential to working with Genesis?

  • Author
    Posts
Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Conditional Action Hook Question’ is closed to new replies.

CTA

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

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 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