Support » Fixing WordPress » Additional nav menu on selected pages only

  • bycelina

    (@bycelina)


    I hope someone can help. I’m using thesis theme 1.8.5 and I have one main nav menu above the header and a secondary nav under the header which works fine. Now I’m trying to create a third nav under the post title of only selected pages. I have managed to create the third menu, only the problem is that it is showing on all posts and pages and not the one page I want it to show.

    Code I have used to register a third menu:

    register_nav_menu('third', 'Third Menu');
    function third_menu() {
    wp_nav_menu( array( 'container_class' => 'third_menu', 'theme_location' => 'third' ) );
    }
    add_action('thesis_hook_before_post','third_menu');

    Then I tried adding the following to have it show on only the 5 selected pages:

    function show_menu() {
      if ( is_page('20046,20847,20845,20841,20812,') )
      {
        if ( has_nav_menu( 'third' ) )
          { wp_nav_menu( array( 'theme_location' => 'third' ) ); }
      }
    }

    What I am trying to create is this: http://damselindior.com/shop/ so if anyone has a better idea of how to create that I am open for suggestions. Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Try it without the single quotes in is_page().

    if ( is_page(20046,20847,20845,20841,20812) )

    Thread Starter bycelina

    (@bycelina)

    Thank you for helping, but unfortunately the menu is still showing on all posts and pages. Do you think perhaps I need to add an if else statement? I’m not really very strong in php so I would try if I knew how to write it. The above codes are a result of copy and paste 🙂

    Moderator keesiemeijer

    (@keesiemeijer)

    I think the ‘thesis_hook_before_post’ action hook inserts it before every post. See if this works:

    register_nav_menu( 'third', 'Third Menu' );
    
    function third_menu() {
    	if ( is_page( 20046,20847,20845,20841,20812 ) ) {
    		if ( has_nav_menu( 'third' ) ) {
    			wp_nav_menu( array( 'container_class' => 'third_menu', 'theme_location' => 'third' ) );
    		}
    	}
    }
    add_action( 'thesis_hook_before_post', 'third_menu' );

    I think this will only insert it for the pages you want, but as this is a commercial theme with its own functionality and support system, I recommend you contact the theme developer for more assistance.

    Moderator keesiemeijer

    (@keesiemeijer)

    Sorry, this needs to be changed for it to work:

    if ( is_page( 20046,20847,20845,20841,20812 ) ) {
    if ( is_page( array( 20046,20847,20845,20841,20812 ) ) ) {

    Thread Starter bycelina

    (@bycelina)

    Brilliant!! That worked! Thank you so much for your help 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Additional nav menu on selected pages only’ is closed to new replies.