Reputation: 13
I'm on my way to build my first Wordpress theme. Now I hit a problem with my menu. It is shown in the source code, but not on the website.
My code in the functions.php
function register_theme_menus() {
register_nav_menus(
array(
'primary-menu' => __( 'Primary Menu' )
)
);
}
add_action( 'init', 'register_theme_menus' );
My code in the header-php
<?php
$defaults = array(
'container' => false,
'theme_location' => 'primary-menu',
'menu_class' => 'no-bullet'
);
wp_nav_menu( $defaults );
?>
What's wrong here. Any ideas?
Thanks!
Upvotes: 1
Views: 137
Reputation:
EDIT:
Add your <nav>
tag below the h1
tag
Use the below Jquery javascript code, I just tested localy your index page and worked fine for me
<script type="text/javascript">
jQuery(".nav-toggle").click(function(event) {
jQuery("nav").toggle('in');
});
</script>
Please change your toggle code because href=""
is empty you must provide a #
<a class="nav-toggle" href=""><span></span>Menu</a>
with
<a class="nav-toggle" href="#"><span></span>Menu</a>
Upvotes: 0
Reputation: 99
Your Menu is registered as of what it shows in view-source but your toggle button is not working, as your toggle button is not linked with the menu so it just refreshed the page.
Your toggle button link is like this:
<a href="" class="nav-toggle"><span></span>Menu</a>
So the href link for toggle button is blank.
Check following link to know how toggle button works:
https://codepen.io/CreativeJuiz/pen/oCBxz
Upvotes: 1
Reputation: 17188
Try this page: https://teamtreehouse.com/community/menu-not-appearing
I also found this page that mentions some context: https://codex.wordpress.org/Function_Reference/register_nav_menus
wp-includes/nav-menu.php
There seems to be a few pages coming into play, so you might be just missing quick edit. I have a good feeling about that first URL though. It mentions fix for very similar if not same issue.
Upvotes: 1