0
votes

I have two menus with the default plugin installed in Wordpress Twenty Fourteen :

  • Menu French
  • Menu English

I have two templates using a different header.php depending on the language.

I want to customize the header.php so I can choose which menu to use.

In header.php there is the following code :

<nav id="primary-navigation" class="site-navigation primary-navigation"
                                                                  role="navigation">
   <button class="menu-toggle">
        <?php _e( 'Primary Menu', 'twentyfourteen' ); ?>
   </button>
   <a class="screen-reader-text skip-link" href="#content">
        <?php _e( 'Skip to content', 'twentyfourteen' ); ?>
   </a>
   <?php wp_nav_menu( array('theme_location'=>'primary','menu_class'=>'nav-menu' ));?>
</nav>

I want to target - Menu English -

I don't know what to add to do so.

3

3 Answers

1
votes

Add

<?php wp_nav_menu( array('menu' => 'Project Nav' )); ?>

see wordpress : http://codex.wordpress.org/Function_Reference/wp_nav_menu

1
votes

You would use the following code in your PHP.

<?php

    $args_en = array(
        'theme_location'  => 'English Menu',
        'menu_class'      => 'menu',
        'menu_id'         => 'en_menu'
    );

    $args_fr = array(
        'theme_location'  => 'French Menu',
        'menu_class'      => 'menu',
        'menu_id'         => 'fr_menu'
    );

?>

<nav id="primary-navigation" class="site-navigation primary-navigation" role="navigation">
   <button id="switch_menu" class="menu-toggle">
        <?php _e( 'Primary Menu', 'twentyfourteen' ); ?>
   </button>
   <a class="screen-reader-text skip-link" href="#content">
        <?php _e( 'Skip to content', 'twentyfourteen' ); ?>
   </a>

   <?php wp_nav_menu( $args_en );?>
   <?php wp_nav_menu( $args_fr );?>

</nav>

<?php wp_nav_menu( $args_en );?> will render the english menu.

<?php wp_nav_menu( $args_fr );?> will render the french menu.

of course since $arg_en contains 'theme_location' => 'english_menu' you will register a menu in functions.php file like so:

add_action('init','My_Menus');
function My_Menus(){
    register_nav_menus(
        array(
            'English Menu' => __('My English Menu'),
            'French Menu' => __('My French Menu'),
        )
    );
};

Then using javascript you can set a default menu to show. The other one will be hidden.

assuming you are using jquery this is the code you need to use:

var fr_menu = $('#fr_menu'), en_menu = $('#en_menu');
en_menu.toggle(true); //shows english menu by default
fr_menu.toggle(false); //hides english menu by default

$('#switch_menu').on('click',function(){
    en_menu.toggle()
    fr_menu.toggle()
})
0
votes

Targeting a specific menu in wordpress for example in header.php, create a menu and copy there name and paste in "Project Name"

wp_nav_menu( array(
    'menu' => 'Project Nav'
) );