custom wordpress menu code example

Example 1: how make custom menu in wordpress

function wpb_custom_new_menu() {
  register_nav_menus(
    array(
      'my-custom-menu' => __( 'My Custom Menu' ),
      'extra-menu' => __( 'Extra Menu' )
    )
  );
}
add_action( 'init', 'wpb_custom_new_menu' );

Example 2: wp main menu

wp_nav_menu( array( 'theme_location' => 'header', 'menu' => 'Main Menu') );

Example 3: add custom css to wordpress menu item

// Wordpress apperance panel settings
1. Go to admin > appearance > menu
2. Click on Screen Options (top right of the screen)
3. Check the CSS classes options in the “Show advanced menu properties” panel
4. add your css classes to the element

Tags:

Misc Example