Support » Fixing WordPress » Assigned Nav Menus on a Per Page Basis using Custom Field

  • Happy New Year Everyone!

    Following several recommendations, I did get a custom menu to display on the page (see below), it was not in the right location, nor did it replace the “default” menu.

    I registered the desired menus by adding the code below to the theme’s functions.php. The newly registered menus now display as shown here

    add_theme_support( ‘nav-menus’ );
    register_nav_menus( array(
    ‘mainnav’ => __( ‘Main Navigation’, ‘NorthVantage’ ),
    ‘corpnav’ => __( ‘Corporate Navigation’, ‘NorthVantage’ ),
    ‘cbonav’ => __( ‘CBO Navigation’, ‘NorthVantage’ ),
    ‘persnav’ => __( ‘Personal Navigation’, ‘NorthVantage’ ),
    ‘youthnav’ => __( ‘Youth Navigation’, ‘NorthVantage’ ),
    ) );

    I then added the code below to my header.php and the desired menu appeared, but not in place of the standard/default menu, and not in the same physical space, as shown here:

    I found the wp_nav_menu in a file other than header.php. I believe the primary related snippet is shown below:

    if(get_option('wpcustomm_enable')!="disable") : // WP3.0 Custom Menu Support
                        $walker = new dyn_walker;
                        'echo' => true,
                        'container' => 'ul',
                        'menu_class'      => 'menu hide-on-phones',
                        'menu_id' => 'dyndropmenu',
                        'theme_location' => 'mainnav',
                        'walker' => $walker
                        if (!class_exists('UberMenu') && get_option('enable_responsive')!='disable') : // check if responsive is disabled
                        'theme_location' => 'mainnav',
                        'container' => 'div',
                        'container_class' => 'hide-on-desktops',
                        'container_id'    => 'nv_selectmenu',
                        'walker'         => new Walker_Nav_Menu_Dropdown(),
                        'items_wrap'     => '<select><option value="">'.__( 'Select a Page', 'NorthVantage' ).'</option>%3$s</select>'

    I really don’t know what to replace above with the code below to replace the default menu with the target menu specified in the custom field menuname of the page/post using the recommended code snippet below, and believe me, I’ve tried LOTS of variables, replacing this and that, adding this, taking that out, et cetera.

    $menu_slug = get_post_meta($post->ID,'menu',true);
    if(is_nav_menu($menu_slug)) {
            'menu' => $menu_slug
    } // optionally, add an else to output something when no menu exists with the given meta value.

    OR this recommended snippet:

    wp_nav_menu( array( 'container' => 'none', 'container_class' => 'menu-header', 'theme_location' => 'primary', 'menu' => get_post_meta( $post->ID, 'MenuName', true) ) );

    Might a knowledgeable WPPHP person be able to assist with the correct code sequence to generate the desired output?

    I would be most appreciative.

  • The topic ‘Assigned Nav Menus on a Per Page Basis using Custom Field’ is closed to new replies.