I am using a blank theme template to create a wordpress theme and I enabled menus by adding the below code to header.php:
<body <?php body_class(); ?>>
<div id="navbar"></div>
<div id="wrapper" class="clear">
<nav>
<?php wp_nav_menu( array('theme_location' => 'primary' ) ); ?>
</nav>
And I added this to functions.php:
if (function_exists('register_nav_menus')) {
register_nav_menus(
array(
'main_nav' => 'Main Navigation Menu'
)
);
};
The menu shows up and works fine when I add links to pages but when I add a custom link to say http://www.google.com with the label Google nothing shows up in the navigation bar. When I view the source the custom link is not being populated at all.
<nav>
<div class="menu">
<ul>
<li class="page_item page-item-9"><a href="http://localhost/wordpress/anatomy/">Anatomy</a></li>
<li class="page_item page-item-11"><a href="http://localhost/wordpress/history/">History</a></li>
<li class="page_item page-item-7"><a href="http://localhost/wordpress/home/">Home</a></li>
</ul>
</div>
</nav>
My css for the nav is simple:
nav {
padding:0;
margin:0;
position:absolute;
width: 900px;
}
nav ul li
{list-style: none;
font-family: 'Numans', sans-serif;
font-size: 15px;
color: #ffffff;
text-align:left;
text-transform: uppercase;
padding: 0;
margin: 0 30px;
display: inline;
position: relative;
top:-32px;
}
nav ul li a {
text-decoration: none;
color: #ffffff;
}
nav ul li a:visited
{color: #ffffff;
}
nav ul li a:hover
{color: #cccccc;
}
nav ul li a:active
{color: #ffffff;
}
I am very new to php and wordpress theming and I can't find anyone online with the same issue.
The issue is that your
theme_location
does not match the name you assigned when you registered the menu.When you registered the menu, you called it
main_nav
. Since you called it that, in order to display that menu, you need to change the call to the menu to referencemain_nav
, like so:wp_nav_menu( array('theme_location' => 'main_nav' ) );