Programmatically adding menu items function replicates in multiple menus

You can use the second input argument $args to target the specific menu. Here’s an example with some checks that you can adjust to your needs: add_filter( ‘wp_nav_menu_objects’, function( $sorted_menu_items, $args ) { if( ‘primary’ === $args->theme_location // Alternative && ‘some_menu_slug’ === $args->menu->slug // Alternative ) { // Your stuff here … } return $sorted_menu_items; … Read more

How can I add a sub menu to an existing navigation menu in WordPress?

I got the answer, here it is: I want to add submenus ffrom database to the menu named ‘Products’ Create a custom plugin and install it through Admin panel. Inside the functions.php write this code. This is upgrade safe way and will not brake if the theme is updated. add_filter( ‘wp_nav_menu_objects’, ‘ravs_add_menu_parent_class’ ); function ravs_add_menu_parent_class( … Read more

Odd behaviour with submenu link creation

On the same page in codex you have this : NOTE: If you’re running into the “You do not have sufficient permissions to access this page.” message in a wp_die() screen, then you’ve hooked too early. So it answers to you question partly. The second part, the following code should work : add_action(‘admin_menu’, ‘my_add_submenu’); function … Read more

How to add more than 1 user role to sub-menu pages

The easiest way is create 2 custom capabilities and assign both to administrators, one to role coach and one to role player. When you create your roles you do something like this: $coach_caps = array( ‘read’ => true, ‘something_else’ => true, ‘can_open_coach_menu’ => TRUE // this is important for your scope ); add_role( ‘coach’, ‘Coach’, … Read more

Hooking into add_submenu_page

Hook into admin_head, the last action before the menu is rendered, and change the global $menu: add_action( ‘admin_head’, ‘wpse_71303_change_menu_cap’ ); /** * Change the capability to access an admin menu item. * * @wp-hook admin_head * @return void */ function wpse_71303_change_menu_cap() { global $menu; foreach ( $menu as $key => $item ) { // Find … Read more

The seventh parameter passed to add_submenu_page()

I was able to track this down to the culprit function add_theme_page(). There There was an additional parameter, per the codex for add_theme_page() that needed to be removed. Removing that seemed to help. function fivehundred_register_admin_menu() { add_theme_page( ‘500 Settings’, ‘500 Settings’, ‘manage_options’, ‘theme-settings’, ‘fivehundred_admin_menu’, plugins_url( ‘/ignitiondeck/images/ignitiondeck-menu.png’ ) ); } add_action( ‘admin_menu’, ‘fivehundred_register_admin_menu’ ); Fixed code … Read more

Menu capability in WordPress

Capability parameter of add_submenu_page() function can only take a single capability, so if you are using the built in roles you can select a capability fro the long list that both administrators and editors have any of these (use any of these freely): moderate_comments manage_categories manage_links unfiltered_html edit_others_posts edit_pages edit_others_pages edit_published_pages publish_pages delete_pages delete_others_pages delete_published_pages … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)