Custom Navigation Menus

Resister Menu

Firstly, in your theme’s functions.php, you need to write a function to register the names of your menus. (This is how they will appear in the Appearance -> Menus admin screen.) As an example, this menu would appear in the “Theme Locations” box as “Header Menu”.

register_nav_menus( array(
‘primary’ => __( ‘Primary Menu’, ‘smoice’ ),
‘top-menu’ => __( ‘Top Menu’ ),
‘footer-menu’ => __( ‘Footer Menu’ )
) );

Display Menus on Theme

Once you’ve done that, your theme will be almost ready. The last preparation step is to tell the theme where you want the menus to show up. You do this in the relevant theme file. So, for example, we might want our header menu to be in header.php. So open up that file in the theme editor, and decide where you want to put your menu. The code to use here is wp_nav_menu which we will need once for each menu location. So, add this code –

<?php wp_nav_menu( array( ‘theme_location’ => ‘primary’, ‘menu_class’ => ‘nav-menu’ ) ); ?>



function register_my_menus() {
'top-menu' => __( 'Top Menu' ),
'footer-menu' => __( 'Footer Menu' )
add_action( 'init', 'register_my_menus' );

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

if ( is_user_logged_in() ) {
} else {
Get menu in page:
<?php wp_nav_menu( array( 'theme_location'=> 'primary', 'menu_class'=> 'menu' ,'container'=> 'none'));?> 


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s