I encountered this problem when I was making a wordpress theme, and encountered a css style error. It is actually very simple. The operation is as follows:
Add the following to functions.php in the theme:
register_nav_menus( array( 'menu' => __( 'menu', '' ), ) );
Paste the navigation code in the theme navigation bar: <?php wp_nav_menu( 'id=navbar' ); ?>
But a css style error occurred :
It turns out that this function outputs the following format:
Copy the code code as follows:
<div id="menubar">
<ul>
<li><a href="http://.../">Home</a></li>
<li><a href="http://.../">Menu item 1</a></li>
<li><a href="http://.../">Menu item 2</a></li>
<li><a href="http://.../">Menu item 3</a></li>
...
</ul>
</div>
It’s okay, just filter it and it’ll be fine:
Change the code to:
Copy the code code as follows:
<?php
echo str_replace("</ul></div>", "", ereg_replace("<div[^>]*><ul[^>]*>", "", wp_nav_menu(array('theme_location' => 'primary', 'echo' => false)) ));
?>