How to register Navigation Menus to your WordPress themes

By default, there are one to two menus in your WordPress themes. Sometime you need to create more menus to show navigation to your site. For example: Top menu, Main menu, Left menu, Right menu, Bottom menu, Footer menu, ect…

This post will help you how to register menus in our WordPress theme by using PHP function to create or register new menu in functions.php, in your WordPress theme, then set new menu item in the Appearance -> Menu, checking menu location that you registed

Register New Menus

Insert bellow code to functions.php file

// Custom Register Menus
function register_main_menus() {
	register_nav_menus(
		array(
			'header-menu' => __( 'Header Menu' ),
			'sidebar-menu' => __( 'Sidebar Menu' ),
			'bottom-menu' => __( 'Bottom Menu' ),
		)
	);
}

Create new menu item

Login to WordPress Dashboard Admin and do step by step

  1. Choose Dashboard -> Appearance -> MenusCreate a new Menu
  2. Create A new Menu and insert Menu itemMenu Structure
  3. Check Theme locations, choose position which you likeWordpress Menu Setting

 

Display your menu on WordPress theme

Open header.php file in your folder theme and insert code bellow to position which you want

<?php wp_nav_menu( array( 'theme_location' => 'header-menu' ) ); ?>

You can replace header-menu with WordPress-readable name you choose

Custom Menu class

You can custom CSS for your menu with class header_menu_class

<?wp_nav_menu( array( 'theme_location' => 'header-menu', 'container_class' => 'header_menu_class' ) ); ?>

Thanks for reading.

Share this :

No comments yet.

Leave a Reply

Related post

Free Responsive Website templates

ThemeVina is Best site for free sharing and download Wordpress themes, Joomla templates, Responsive website templates and more HTML templates.

All template in Site are free. You can download and install for your site.

Contact us

  • Brand: Theme Vina
  • Email: admin@themevina.com
  • Website: www.themevina.com
  • Address: 367 Tran Hung Dao Street
  • Location: Thai Binh City, Thai Binh, Viet Nam

Newsletter