Conditional Menu With Genesis Framework

Another tutorial on Genesis Framework. By default, Genesis comes with two menus – Primary and Secondary Menus. This is really great and gives more flexibility to do further customization on your website.

Sometimes you might want to use different menu on specific post and page. There are two ways to achieve this in Genesis, and in this tutorial I’ll show you both of them.

  1. Conditional Menu with Code Snippets

Love hardcoding or just want to use less plugins? So this is a useful snippet to do this.

/** Conditional secondary menu **/

add_action(‘template_redirect’, ‘wpsp_conditional_actions’);

function wpsp_conditional_actions() {
if ( is_page( 10 ) )
remove_action(‘genesis_after_header’, ‘genesis_do_subnav’);
}

  1. Is_page is the WordPress conditional tags. You may also use it for multiple posts and page or with other conditional tags such as is_home etc. Please refer to WordPress Conditional Tags in WordPress Codex for more info.
  2. 10 in the bracket is the ID of post/page. Use Reveal IDs plugin to help you find out the ID of the post or page.
  3. genesis_after_header is a hook specifically use with Genesis Framework. This is the default location for Secondary Menu in Genesis. See the Genesis Hook Reference page on StudioPress for more info. I also recommend using Genesis Visual Hook plugin to make life easier.
  4. What the code do is basically remove the secondary menu in post with ID: 10.

To make primary menu as the conditional menu, replace genesis_do_subnav with genesis_do_nav.

  1. Conditional Menu with Genesis Simple Menus plugin

This Genesis Simple Menus plugin was developed by StudioPress, the maker of Genesis Framework. The Genesis Simple Menus is available from WordPress.org Plugin repository for free.

  1. Install and activate the plugin.
  2. Create your menu. If you’re not familiar to this, read my tutorial – WordPress101: Using WordPress Menu.
  3. Every time you open the post editor for post and page, you will see a new metabox. This is where you specify the menu to be used for that specific post and page. Of course you are able to create as many menu as you wish and choose them from the dropdown.

WordPress Conditonal Menu

Please note that this plugin uses your secondary menu. So make sure you don’t remove them.

I found using plugin gives you more flexibility since you can create as many custom menu as you wish and use it at different places. This plugin was developed by StudioPress, so you can assure that the plugin is compatible with most Genesis child themes.