Custom Menu in Wordpress


Working with Wordpress premium or custom design theme and need additional menu in your Wordpress? Cool, Wordpress allow us to add number of menu according our need by simple register custom menu in WP using WP function register_nav_menu
<?php
add_action( 'after_setup_theme', 'register_my_menu' );
function register_my_menu() {
  register_nav_menu( 'top_menu', __( 'Top Menu', 'theme-text-domain' ) );
}

//top_menu (required) which is Menu location identifier, like a slug.
//Top Menu (required) Menu description which for identifying the menu in Back-end Appearance >> Menus .
?>
After finish Custom menu registration in WP now its time to assign some menu elements which we want to display by them.
Go to Wp-admin >> Appearance >> Menus
create your new Menu with add Menu Elements (Page, Post, Category or Custom Link) and assign it your created custom menu. in our cases Customer Register menu 'Top Menu' see below image...



Now its time to get display custom register menu in front end. point code location where you want to set New register menu.
If you want to set it in header area than find your active theme header.php and add following code

<?php
    
if ( has_nav_menu( 'Top Menu' ) ) {
    wp_nav_menu( array(
 'theme_location' => 'top_menu',
 'container'      => false,
 'menu_class'     => 'lfloat',
     ) );
   }
?>

Post a Comment

0 Comments