We help IT Professionals succeed at work.

Force secondary Nav to display on certain pages

soujohn asked

I’m having an issue with a secondary navigation that doesn’t appear on certain page views of a calendar plugin that I’m using called The Events Calendar Pro. It doesn’t appear on pages other than those I have in the sub menu (Main page & Events Calendar page). I’ve discovered that this is not an issue with the Events Calendar plugin, or the theme I'm using. I’ve posted on each of their forums and support sections. It’s actually an issue with a feature that I’m using to display submenu items as a secondary navigation. I found the code for this plugin here:

It allows you to display a secondary navigation based on the menu you create in the ‘Appearance > Menus’ section of the WP backend. However, because I have not added every event view to the Events section of my menu the secondary nav bar doesn’t show up on the other view or on individual event pages. Adding all the event views and event pages would be tedious and would look really cluttered.

So now here is my question: How can I have the secondary menu that appears on the main Events page appear on all pages that are created by The Events Calendar plugin? Is there someway to hard code something into the .php file of the calendar plugin so that my nav always displays? Or some conditional statement I can code into my header.php file to make sure that my nav appears on Event pages even if they are not included in the submenu structure?

Here are some links to view:
http://casbaa.thinkcreativeinc.com/wordpress/events/ (does appear)
http://casbaa.thinkcreativeinc.com/wordpress/events/list/ (doesn’t appear)


Watch Question

Jason C. LevineDon't talk to me.
Easiest way to do it is in header.php (where the menu functions most likely live).

1) Get the page IDs for the Event Calendar created pages (just hover on Edit in All Pages and write the ID numbers down)

2) Open header.php and look for references to the secondary menu...it should be right under the primary menu code.

3) Modify the code so it looks something like the following:

if ( is_page( array( 'xx','yy',zz' ) ) )
  if ( has_nav_menu( 'secondary' ) ) // or whatever the secondary Events menu is called
  { wp_nav_menu( array( 'theme_location' => 'secondary' ) ); } // or whatever the location is called

Open in new window


Jason, thanks. I'll give this a try.
After quite a bit of trial-and-error I asked the original plugin creator, Christian Varga, who developed the sub menu feature I was trying to implement. Turns out that he developed a modified version of the plugin for forcing a submenu onto a page by referencing the menu item id from another page using the submenu you would like to duplicate.

Even though the code was provided; I still ran in to trouble trying to implement myself. And it turned out that I had a couple syntax issues (e.g., wrapping the root id in quotes when I wasn't supposed to & placing the full "menu-item-number" instead of just the actual number). After I figured that out the submenu displayed as I intended.

Here is the code that I used. I used an if/else statement that searched for a specific body class ('single-tribe_events'), and if the loaded page used that body class it would force display the submenu found on the Main Events page (which uses menu-item-id-389). Else it would display whatever submenu was created for that page.

	$classes = get_body_class();
		if (in_array('single-tribe_events',$classes)) {
		wp_nav_menu( array( 'theme_location' => 'primary', 'sub_menu' => true, 'root_id' => 389	) );
	} else{
		wp_nav_menu( array( 'theme_location' => 'primary', 'sub_menu' => true, 'direct_parent' => true) );

Open in new window

Thanks for the help


My comment links to a bit of modified code that was created specifically to solve the issue I was having. Anyone with a similar issue may find that link helpful.