WordPress移动端菜单无法点击求助(已尝试主流方案未解决)
Hey there, let's work through this mobile menu issue you're hitting with WordPress 4.9.5. Since you've already ruled out plugin conflicts and checked the TwentyEleven theme scripts, here are some targeted steps to narrow down and fix the problem:
Verify the Mobile Menu Trigger Script
TwentyEleven's mobile menu relies on JavaScript to toggle thedisplayproperty of the menu<ul>. It's possible the update disrupted this script, or it was accidentally modified.- Open your theme's
header.phpfile and check for a click handler on the menu toggle button (usually with classmenu-toggle). If it's missing, add this basic toggle logic:jQuery(document).ready(function($) { $('.menu-toggle').on('click', function() { $('#access ul').toggle(); // Replace with your menu ul's actual selector if needed }); }); - Double-check
functions.phpto ensure the navigation script is properly enqueued. Look for a line like this:
If the path is incorrect or the script isn't loading, update the URI to match your theme's file structure.wp_enqueue_script('twentyeleven-navigation', get_template_directory_uri() . '/js/navigation.js', array('jquery'), '20120206', true);
- Open your theme's
Fix CSS Priority Conflicts
Sometimes even with working JS, overly specific CSS rules can keep the menu hidden. Try adding these custom styles to your theme's Additional CSS section orstyle.css:/* Default state: hide mobile menu */ #access ul { display: none !important; } /* Active state: show menu when toggle is clicked */ #access ul.mobile-menu-active { display: block !important; }Then adjust the JS to toggle an
activeclass instead of directly changingdisplay:jQuery(document).ready(function($) { $('.menu-toggle').on('click', function() { $('#access ul').toggleClass('mobile-menu-active'); }); });Check Menu Assignment & Hook Compatibility
WordPress 4.9.x made minor tweaks to menu hooks. Confirm your menu is assigned correctly:- Go to Appearance > Menus in your WP admin and ensure your menu is set to the "Primary" theme location (or the location your theme uses).
- In
header.php, verify thewp_nav_menucall uses the correcttheme_location:<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) ); ?>
Clear Caches to Rule Out Stale Files
Old cached JS/CSS files can prevent new fixes from taking effect. Try:- Clearing your browser's cache and testing in incognito mode.
- If you use a CDN or caching plugin, flush its cache completely.
- For quick testing, add a dynamic version number to your enqueued script to force a refresh:
(Remember to revert to a fixed version number once the issue is resolved.)wp_enqueue_script('twentyeleven-navigation', get_template_directory_uri() . '/js/navigation.js', array('jquery'), time(), true);
Give these steps a shot—if none resolve the problem, we can dive deeper into your theme's specific code. Hope this helps!
内容的提问来源于stack exchange,提问作者Khushbu Vaghela

