• 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 secondary menu

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 secondary menu

This topic is: resolved

Tagged: conditional menu

  • This topic has 5 replies, 3 voices, and was last updated 8 years, 11 months ago by Genesis Developer.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • August 6, 2016 at 3:33 pm #190840
    bburro
    Member

    Greetings all! I am looking for a little help on a piece of code for my functions.php file. Here's what I'n trying to do:

    If page ID = (pageID1, pageID2, pageID3) => display secondary menu 1;

    If page ID = (pageID3, pageID4, pageID5) => display secondary menu 2;

    Else do not display secondary menu.

    I am using the showcase 3rd party template, and haven't heard back from the author.

    Thanks in advance!

    http://localhost
    August 6, 2016 at 4:15 pm #190842
    Victor Font
    Moderator

    http://victorfont.com/conditional-secondary-menus-genesis-themes/


    Regards,

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

    August 6, 2016 at 5:23 pm #190847
    bburro
    Member

    Victor- I was looking at the revisited version of your page and my coding skills weren't up to connecting the dots.-

    Let me give this one a go. Thanks!

    August 6, 2016 at 5:33 pm #190849
    bburro
    Member

    My coding skills are meager at best. One of the menus I want to use has an ID of menu-hydrovac-menu.

    What would the code be to use that menu on pages with IDs of 1,4 &5?

    I can take that and create the other blocks.

    Also, what would the last part be that says "otherwise don't display a secondary menu"?

    Thanks again for the help!

    August 6, 2016 at 6:05 pm #190851
    bburro
    Member

    It looks like what I want is more like the version on your revisited page, except I want default to be NO SECONDARY NAV.

    What variable are you passing as Menu1, Menu2? Is that the ID?
    How do I assign multiple page IDs? separate them by a comma?
    How do I default to where if none of the IDs I have selected, then no secondary nav?

    The following is the code from your site I am referring to, just to make sure we are on the same page.

    Thanks again!

    //* When a new page is selected from the primary menu,
    //* execute the change_secondary_menu function
    add_action( 'template_redirect', 'change_secondary_menu' );
    function change_secondary_menu() {
     
        //* Do nothing if menu not supported
        if ( ! genesis_nav_menu_supported( 'secondary' ) )
            return;
     
        add_filter( 'wp_nav_menu_args', 'choose_secondary_nav_menu' );
     
    }
     
    function choose_secondary_nav_menu( $args ) {
     
        if ( $args['theme_location'] == 'secondary' ) {
     
            //* default secondary menu
            $args['menu'] = 'Menu1';
     
            if( is_page( 37 ) ) {
                $args['menu'] = 'Menu2';
            }
     
            if( is_page( 39 ) ) {
                $args['menu'] = 'Menu3';
            }
     
        }
        return $args;
    }
    August 6, 2016 at 11:03 pm #190852
    Genesis Developer
    Member

    This can give you the idea http://genesisdeveloper.me/different-primary-menu-on-pages-using-altitude-pro-theme/

    I think that you do not need the 'template_redirect' action. You ca directly target the 'wp_nav_menu_args' filter.


    Download Genesis Featured Posts Combo Widget | Simple Grid Layouts Plugin for Posts, CPTs and terms
    You can request new tips/help.

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

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