0

I am attempting to create multiple menus for separate pages on a Wordpress website. I would like the theme to load Primary Menu, unless the individual page specifies a different one through the Custom Fields.

Attempting to add this code to the Header.php, yet having issues with the themes custom settings, as the php does not have a "wp_nav_menu".

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

When I add this directly to the current code, it causes the Main Menu to double up on top of the already existing custom menu from the theme. Here is the themes header.php existing code:

<?php do_action( 'presscore_body_top' ); ?>

<div id="page"<?php if ( 'boxed' == of_get_option('general-layout', 'wide') ) echo ' class="boxed"'; ?>>

 <?php if ( of_get_option('top_bar-show', 1) ) : ?>

<?php get_template_part( 'templates/header/top-bar', of_get_option('top_bar-content_alignment', 'side') ); ?>

<?php endif; // show top bar ?>

<?php if ( apply_filters( 'presscore_show_header', true ) ) : ?>

<?php get_template_part( 'templates/header/header', of_get_option( 'header-layout', 'left' ) ); ?>

<?php endif; // show header ?>

<?php do_action( 'presscore_before_main_container' ) ; ?>

<div id="main" <?php presscore_main_container_classes(); ?>><!-- class="sidebar-none", class="sidebar-left", class="sidebar-right" -->

 <?php if ( presscore_is_content_visible() ): ?>

    <div class="main-gradient"></div>

    <div class="wf-wrap">
        <div class="wf-container-main">

            <?php do_action( 'presscore_before_content' ); ?>

<?php endif; ?>

Where in this code can I create this option for individual pages to pull for a separate menu?

1 Answer 1

0

Don't use the menu array key. Instead, use the theme_location key for your menu. (You can exclude menu entirely.) So something like:

wp_nav_menu( array(
  'container' => false,
  'theme_location' => get_post_meta( $post->ID, 'MenuName', true) ? get_post_meta( $post->ID, 'MenuName', true) : 'primary'
) );

If there's no custom menu, it will fall back to 'primary'. Side note: container_class is useless if you specify no container so either use a container or remove container_class.

1
  • My issue here is understanding where to place this code within the existing header.php. When I place it within the code, it causes a 2nd menu to load on top of the existing. How do I get the current code to register this feature without loading a duplicate menu? Thanks for taking the time to help. Dec 27, 2014 at 23:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.