Skip to content

Instantly share code, notes, and snippets.

@BeholdPL
Created March 22, 2021 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BeholdPL/4dd06a6470f025b5b0e5dca807c754e8 to your computer and use it in GitHub Desktop.
Save BeholdPL/4dd06a6470f025b5b0e5dca807c754e8 to your computer and use it in GitHub Desktop.
Register new #menu #wordpress
<?php
// menu
register_nav_menus( array(
'main_menu' => __( 'Primary Menu', 'text-domain' );
// other stuff
);
// primary menu
function registerPrimaryMenu() {
register_nav_menu( 'primary', __( 'Primary Menu', 'text-domain' ) );
}
add_action( 'after_setup_theme', 'registerPrimaryMenu' );
// calling menu
wp_nav_menu(
array(
'container_class' => 'customContainerMenu', // custom menu container ID
'container_id' => 'customContainerID', // custom menu container class
'menu_class' => 'customMenuClass', // custom menu class
'menu_id' => 'customMenuID', // custom menu ID
'fallback_cb' => 'wp_page_menu', // which menu is called by dfault
'depth' => 1, // depth of nested menus, 0 is all, 1 is 1st levet
'theme_location' => 'main_menu', // registered menu
// more: https://developer.wordpress.org/reference/functions/wp_nav_menu/
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment