Reputation: 2293
I need to create a navigation menu in wordpress when i activate my theme.
I have some pages created at the time of theme activation and i need to add these pages to the navigation menu .
I had created the menus using register_nav_menu
, but i cant add the pages under this menu .
Please help me Regards
Upvotes: 1
Views: 576
Reputation: 1744
Just write in your functions.php // To add Orders as main menu after dasboard.
http://codex.wordpress.org/Function_Reference/add_dashboard_page
function dasboard_sub_menu() {
global $menu;
global $submenu;
$menu[6] = array( __('Orders'), 'read', 'edit.php?post_type=shop_order', '', 'menu-top menu-top-first menu-icon-orders', 'menu-dashboard', 'none' );
$menu[7] = array( __('Catalogue'), 'read', 'edit.php?post_type=product', '', 'menu-top menu-top-first menu-icon-catalogue', 'menu-dashboard', 'none' );
$menu[8] = array( __('Coupons'), 'read', 'edit.php?post_type=shop_coupon', '', 'menu-top menu-top-first menu-icon-coupon', 'menu-dashboard', 'none' );
//$menu[4] = array( '', 'read', 'separator1', '', 'wp-menu-separator' );
$menu[59] = array( '', 'read', 'separator2', '', 'wp-menu-separator1' );
$menu[99] = array( '', 'read', 'separator3', '', 'wp-menu-separator2' );
$menu[56] = array( '', 'read', 'separator4', '', 'wp-menu-separator3' );
$menu[57] = array( '', 'read', 'separator5', '', 'wp-menu-separator4' );
$submenu[ 'index.php' ][1] = array( __('Reports'), 'read', 'admin.php?page=woocommerce_reports' );
}
add_action( 'admin_menu', 'dasboard_sub_menu' );
// To add Submenu Orders under Dashboard Sub Menu
// To add Orders as main menu after dasboard
Upvotes: 1
Reputation: 91
Have you tried the wp_update_nav_menu_item() function?
wp_update_nav_menu_item(
$id_of_menu,
0, /* Use 0 to create a new menu item */
array(
'menu-item-title' => 'Title',
'menu-item-classes' => 'title',
'menu_item_url' => 'url',
'menu_item_status' => 'published')
);
That should do the trick for you! Have a look at http://www.acousticwebdesign.net/wordpress/how-to-create-wordpress-3-navigation-menus-in-your-theme-or-plugin-code/ for more in depth info.
Upvotes: 1