Skip to content

Instantly share code, notes, and snippets.

@IgnacioGaldames
Last active August 29, 2015 14:17
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 IgnacioGaldames/47e0e20a22ee7f7db64e to your computer and use it in GitHub Desktop.
Save IgnacioGaldames/47e0e20a22ee7f7db64e to your computer and use it in GitHub Desktop.
Wordpress menus via Functions
$menu_exists = wp_get_nav_menu_object( 'custom-menu');
// If it doesn't exist, let's create it.
if( !$menu_exists){
register_nav_menus(
array(
'custom-menu' => 'Mi Custom Menú',
)
);
$menu_id = wp_create_nav_menu('Mi Custom Menú');
wp_update_nav_menu_item($menu_id, 0, array(
'menu-item-title' => __('Item 1'),
'menu-item-url' => home_url( '/item-1' ),
'menu-item-status' => 'publish'));
wp_update_nav_menu_item($menu_id, 0, array(
'menu-item-title' => __('Item 2'),
'menu-item-url' => home_url( '/item-2' ),
'menu-item-status' => 'publish'));
}
if ( $menu_id > 0 ) {
// set our new MENU up at our theme's nav menu location
set_theme_mod( 'nav_menu_locations' , array( 'custom-menu' => 'Mi Custom Menú' ) );
// add a menu item to that new menu
}
//end custom menu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment