Skip to content

Instantly share code, notes, and snippets.

@remkus
Created March 22, 2012 18:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remkus/2161816 to your computer and use it in GitHub Desktop.
Save remkus/2161816 to your computer and use it in GitHub Desktop.
Pre populate Custom Menus
<?php
add_action( 'init', 'add_menus' );
function add_menus() {
register_nav_menus( array( 'main_nav' =--> 'The main menu', ) );
$new_menu_id = wp_create_nav_menu( 'Main Menu' );
$page_args = array(
'menu-item-object-id' => 1,
'menu-item-object' => 'page',
'menu-item-parent-id' => 0,
'menu-item-type' => 'post_type',
'menu-item-title' => 'THIS WILL BE THE LINK TITLE',
'menu-item-status' => 'publish',
);
if ( $new_menu_id > 0 ) {
// set our new MENU up at our theme's nav menu location
set_theme_mod( 'nav_menu_locations' , array( 'main_nav' => $new_menu_id ) );
// add a menu item to that new menu
wp_update_nav_menu_item( $new_menu_id , 0, $page_args );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment