Additional Menu in TwentyTwelve is not working in mobile
-
I have successfully added a second menu in a Twenty Twelve child theme. I used Zeak’s tutorial which has been referenced several times here on the forums. It works, except that the mobile menu buttons are not working properly.
There is a javascript that is is used on there and it is supposed to dequeue the existing TwentyTwelve menus and work in the double-menus. However it does not when I test in a small size and the result is that my upper menu is “open” with all the links below and will not toggle closed, while by lower menu will not toggle and is stuck “closed”.
I have re-created this on a public development site of mine so that you can see the two menu sections. (The actual site is not public yet and is on a hidden development domain.)
Here are the relevant bits of code for reference….
From the header ———–
<!-- Upper Navigation --> <nav id="upper-navigation" class="upper-navigation" role="navigation"> <h3 class="menu-toggle"><?php _e( 'Page Menu', 'twentytwelve' ); ?></h3> <div class="skip-link assistive-text"><a href="#content" title="<?php esc_attr_e( 'Skip to content', 'twentytwelve' ); ?>"><?php _e( 'Skip to content', 'twentytwelve' ); ?></a></div> <?php wp_nav_menu( array( 'theme_location' => 'secondary', 'menu_class' => 'nav-menu', 'fallback_cb' => false ) ); ?> </nav> <!-- #lower-navigation --> <nav id="site-navigation" class="main-navigation" role="navigation"> <h3 class="menu-toggle"><?php _e( 'Category Menu', 'twentytwelve' ); ?></h3> <a class="assistive-text" href="#content" title="<?php esc_attr_e( 'Skip to content', 'twentytwelve' ); ?>"><?php _e( 'Skip to content', 'twentytwelve' ); ?></a> <?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) ); ?> </nav><!-- #site-navigation -->
From the Functions ———–
// de-queue navigation js add_action('wp_print_scripts','tto_dequeue_navigation'); function tto_dequeue_navigation() { wp_dequeue_script( 'twentytwelve-navigation' ); } // load the new navigation js function tto_custom_scripts() { // Register the new navigation script wp_register_script( 'lowernav-script', get_stylesheet_directory_uri() . '/js/navigation.js', array(), '1.0', true ); // Enqueue the new navigation script wp_enqueue_script( 'lowernav-script' ); } add_action( 'wp_enqueue_scripts', 'tto_custom_scripts' ); // Add the new menu register_nav_menus( array( 'primary' => __( 'Category Menu (Green Bar)', 'tto' ), 'secondary' => __( 'Page Menu (Above Green Bar)', 'tto'), ) );
The Javascript ——————–
// JavaScript Document // Lower Navigation ( function() { var button = document.getElementById( 'upper-navigation' ).getElementsByTagName( 'h3' )[0], menu = document.getElementById( 'upper-navigation' ).getElementsByTagName( 'ul' )[0]; if ( undefined === button ) return false; // Hide button if menu is missing or empty. if ( undefined === menu || ! menu.childNodes.length ) { button.style.display = 'none'; return false; } button.onclick = function() { if ( -1 == menu.className.indexOf( 'nav-menu' ) ) menu.className = 'nav-menu'; if ( -1 != button.className.indexOf( 'toggled-on' ) ) { button.className = button.className.replace( ' toggled-on', '' ); menu.className = menu.className.replace( ' toggled-on', '' ); } else { button.className += ' toggled-on'; menu.className += ' toggled-on'; } }; } )();
I’m not versed in javascript to know what’s wrong. And Zeak admits this himself. I’ve asked a couple others here on the related boards, but I’m afraid their several-month old topics are not being noticed via email.
So I post this and wonder if anyone can see an obvious problem.
- The topic ‘Additional Menu in TwentyTwelve is not working in mobile’ is closed to new replies.