Registering Your Menu In wordpress
To position your newly created menu on your theme you will first need to register a new menu.
In your functions.php page copy the following code.
function register_menu() {
register_nav_menu('primary-menu', __('Primary Menu'));
}
add_action('init', 'register_menu');
The register_nav_menu function requires two parameters the location of the menu and the description.
register_nav_menu( $location, $description );
Displaying The Menu
Where you want to display this menu open the file for example the header.php file and paste the following code.
if ( has_nav_menu( 'primary-menu' ) ) { /* if menu location 'primary-menu' exists then use custom menu */
wp_nav_menu( array( 'theme_location' => 'primary-menu') );
}
The wp_nav_menu function will display a theme menu by providing it with a menu theme location.
Assign Menu
Finally we can assign the primary-menu to your newly created menu. Go back to the menu page in the dashboard find your new menu and assign this menu in your theme location.
Comments
Post a Comment