• 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 Menu Not Working

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 Menu Not Working

This topic is: not resolved
  • This topic has 2 replies, 2 voices, and was last updated 4 years, 8 months ago by mstarks01.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • November 19, 2017 at 4:52 pm #213758
    mstarks01
    Member

    I have modified some code (thanks to Victor Font), which attempts to display a secondary menu based on certain conditions.

    If I implement it as listed below, it seems to work fine (that is, the menu is displayed correctly according to the category); however, if I uncomment the section about the custom post types (which are LearnDash post types), the entire Primary menu goes blank sans for a login link. What am I doing wrong?

    
    add_action( 'template_redirect', 'change_primary_menu' );
    function change_primary_menu() {
     
        //* Do nothing if menu not supported
        if ( ! genesis_nav_menu_supported( 'primary' ) )
            return;
     
        add_filter( 'wp_nav_menu_args', 'choose_primary_nav_menu' );
     
    }
     
    function choose_primary_nav_menu( $args ) {
     
        if ( $args['theme_location'] == 'primary' ) {
     
            //* default primary menu
            	$args['menu'] = 'Primary Navigation';
     
            if ( in_category( 'Member Only' ) ) {
                $args['menu'] = 'Secondary Navigation';
            }
    	  
    	    //* Ensure that the secondary menu applies to all LearnDash content
    	    //*if ( 'sfwd-courses' || 'sfwd-lessons' || 'sfwd-quiz' || 'sfwd-topic' || 'sfwd-certificates' == get_post_type() ) {
               //* $args['menu'] = 'Secondary Navigation';
           //* }
        }
        return $args;
    }
    
    November 20, 2017 at 4:50 am #213771
    Victor Font
    Moderator

    Your if statement is wrong. I would write it this way:

    $my_post_type = get_post_type();
    if ( $my_post_type == 'sfwd-courses' || $my_post_type == 'sfwd-lessons' || $my_post_type == 'sfwd-quiz' || $my_post_type == 'sfwd-topic' || $my_post_type == 'sfwd-certificates' )

    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    November 20, 2017 at 12:17 pm #213797
    mstarks01
    Member

    Thanks, Victor. You're always helpful and it is very much appreciated!

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 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

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