Support » Fixing WordPress » Create non-dropdown sub menu

  • Resolved vovazuev

    (@vovazuev)


    Hi!

    I have a main menu made of pages. Some of the pages need to have sub menus. I mean, when I go to the specific page, there has to appear an additional menu underneath the main menu. Each sub menu item should lead to a separate page (thus tabs won’t work). An example of such functionality can be seen here:

    http://lostpinesbiblechurch.org/audiofiles.asp

    I would really appreciate an advice on how to achieve that menu functionality with WP.

    Thanks!

    • This topic was modified 1 month ago by  vovazuev.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    The dropdown is carried out in CSS by your theme or sometimes by a plugin. Which theme is this regarding?

    vovazuev

    (@vovazuev)

    I’m working with the blank theme. I need a static sub menu, not dropdown.

    Moderator Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Yeah I get you. That’s not a theme we support though: https://wordpress.org/themes/blank/ – We only support themes on WordPress.org.

    Moderator bcworkz

    (@bcworkz)

    You can alter the menu produced by WP through the “wp_nav_menu” filter. Your filter callback could add additional menu items, or alter existing ones, or add entirely unrelated HTML if you wanted to. There are also several other hooks we can use to customize the output of wp_nav_menu(), up to specifying a custom walker for ultimate control. Review the wp_nav_menu() source code for these options.

    But if you are adding a sub menu that appears under the main menu, you could just have your template output the desired HTML directly without involving wp_nav_menu() at all.

    OR you could add a secondary menu area to your theme where users can specify the sub menu content that will appear in this secondary area.

    There are many variations on these approaches, what is optimal depends on exactly what you wish to accomplish, not just on the page itself, but for any back end UI that may be required.

    vovazuev

    (@vovazuev)

    Okay, I solved this task by adding a secondary menu to specific pages and then forcing the main menu item to be active when I’m on those pages.

    I used the following function:

    function special_nav_class( $classes, $item ){
    	if(is_page('page-one') || is_page('page-two') || is_page('page-three')) {	
    		if( $item->title == 'Page Title' ){ 
    			$classes[] = "desired-class";
    		}
    		return $classes;
    		} else {
    			return $classes;
    		}
    	}
    add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);
Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.