how to add menu in wordpress 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: how make custom menu in wordpress
<?php
wp_nav_menu( array(
'theme_location' => 'my-custom-menu',
'container_class' => 'custom-menu-class' ) );
?>
Example 3: add top menu bar in wordpress
function register_my_menu() {
register_nav_menu('additional-menu',__( 'Additional Menu' ));
}
add_action( 'init', 'register_my_menu' );
Example 4: create 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' );
<?php
wp_nav_menu( array(
'theme_location' => 'my-custom-menu',
'container_class' => 'custom-menu-class' ) );
?>
Example 5: how add administration menu in wordpress
<?php
/** Step 2 (from text above). */
add_action( 'admin_menu', 'my_menu' );
/** Step 1. */
function my_menu() {
add_options_page( //this code Add submenu page to the Settings main menu
'My Options',
'My Menu', //this paramenter display menu option in administration setting
'manage_options',
'my-unique-identifier',
'my_options'
);
}
/** Step 3. */
function my_options() {
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
echo 'Here is where I output the HTML for my screen.';
echo '</div><pre>';
}
?>