how to create menu in wordpress themes

how to create menu in wordpress themes

From wordpress 3.0 release wordpress launched the custom navigation Menu in wordpress admin panel. wordpress tutorial for, how to create menu in wordpress themes. Through drag and drop you can manage the menus. Using this menus are very easy for users.

how to create menu in wordpress themes

how to create menu in wordpress themes
how to create menu in wordpress themes

You can check wordpress admin section for managing the menus in wordpress theme.

In this article I will show you how to enable Custom menu for your wordpress theme.

If you want to create the one menu in wordpress theme then just open the functions.php file and put following code in that file.


add_theme_support( 'menus' );

If you want to create or use the multiple menus in wordpress theme then just open the functions.php file and put following code in that file.


add_action( 'init', 'register_my_menus' );

function register_my_menus() {
 register_nav_menus(
 array(
 'primary-menu' => __( 'Main Menu' ),
 'secondary-menu' => __( 'Top Menu' ),
 'tertiary-menu' => __( 'Footer Menu' )
 )
 );
}

After this adding code in functions.php file you need to open the header.php and footer.php file.

For single menu you need to add following code in header.php file.


<?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'container_class' => 'menu-header' ) ); ?>

For multiple menu you need to add following code in header.php or footer.php file

# Following code for Top Menu


wp_nav_menu( array( 'theme_location' => 'secondary-menu', 'sort_column' => 'menu_order', 'container_class' => 'nav' ) );

#Following code for Main Menu


&lt;?php wp_nav_menu( array( 'theme_location' => 'primary-menu', 'sort_column' => 'menu_order', 'container_class' => 'nav' ) ); ?>

#Following code for Footer Menu


&lt;?php wp_nav_menu( array( 'theme_location' => 'tertiary-menu' ) ); ?>

Above code will give you the more control over the wordpress theme. If you have any doubts or questions then please do write to me.

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

Leave a Reply

Your email address will not be published.