• Hi

    I am looking a way to add a horizontal secondary menu in my theme. I have tried adding

    add_action( 'init', 'register_secondary_menu' );
    function register_secondary_menu() {
        if ( function_exists( 'register_nav_menu' ) ) {
            register_nav_menu( 'secondary-menu', 'Secondary Menu' );
        }
    }
    
    add_action('__header', 'display_secondary_menu', 1000, 0);
    function display_secondary_menu() {
    	echo ( has_nav_menu( 'secondary-menu' ) ? wp_nav_menu (
            array (
                'theme_location' => 'secondary-menu',
    			'container_id'    => 'secondary-menu',
    			'container_class'    => 'secondary-menu'
            )
        ).'<div class="clearall"></div>' : '' );
    }

    in my child theme. This has created a new menu location. But when I assign some menu to that location it is still not displayed.

    I am using twentyFourteen theme on a localhost PC

Viewing 5 replies - 1 through 5 (of 5 total)
  • are you placing the wp_nav_menu in the theme or functions.php. It should be placed at the location in the theme where you want the menu to be located. The register_nav_menu belongs in the functions.php.

    Thread Starter bharara

    (@bharara)

    I have placed it in the functions.php of my child theme

    What theme are you using? Does your theme define __header as an action hook (i.e., by calling do_action( '__header' ) at some point)?

    The wp_nav_menu function doesn’t go in the functions.php file. You need to place it in the theme where you want the menu to appear. It acts like a place holder for the menu.

    Thread Starter bharara

    (@bharara)

    Where I EXACTLY have to place it?

    In the head section or at the end of the header

    I am using twentyFourteen Theme

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding a secondary horizontal menu’ is closed to new replies.