Something like this should work. $handle
should be the menu’s slug; set $sub
to true to search submenus (defaults to top level menus):
function find_my_menu_item( $handle, $sub = false; ){
if( !is_admin() || (defined('DOING_AJAX') && DOING_AJAX) )
return false;
global $menu, $submenu;
$check_menu = $sub ? $submenu : $menu;
if( empty( $check_menu ) )
return false;
foreach( $check_menu as $k => $item ){
if( $sub ){
foreach( $item as $sm ){
if($handle == $sm[2])
return true;
}
} else {
if( $handle == $item[2] )
return true;
}
}
return false;
}
One last quick note: this should not be used before the menu is set. 'admin_init'
is a safe bet for the earliest time to use this. I also added some code to leave gracefully if the menus aren’t set.
Related Posts:
- WordPress admin menu formatting issue
- The Great WordPress Admin Menu Challenge of Jan 2011 (a.k.a. How to Resolve Some Challenges when Modifying the WordPress Admin Menu System?)
- Remove duplicate main – submenu in admin?
- Plugin View Details Link
- Add an admin page, but don’t show it on the admin menu
- Getting custom admin submenu item to highlight when its active
- Add update notification bubble to admin menu item?
- Are there any reasons you can’t use strings for admin menu positions?
- remove_menu_page doesn’t work on custom plugin menus
- List table not rendering when $this->items is filled
- Order Admin sub-menu items?
- How Can I remove or hide the export page in WordPress menu?
- How to hide menu on WordPress admin
- custom admin menu with custom filed
- Add highlighting to new Admin Dashboard Menu Item
- Theme editor menu item refuses to go away
- Remove menus and submenus
- Highlighting a Menu Item by Post Name
- How to remove the Plugins Editor from the admin menu
- add logout button on admin side menu
- Admin custom option screen not saved unless user manage_options capability
- How to remove_menu_page added by a plugin that appears to have no referenceable slug
- Admin page menu keeps bugging out
- Admin Menu – Highlight top-level menu when on a sub-menu page (without showing sub-menu)
- Show admin menu and toolbar in admin post page
- Edit Page or Post from Top Admin Bar
- How to change menu page capability
- WordPress add_options_page() function not considering role
- How to determin which admin screen/sub screen I’m currently viewing
- Add post-new.php?post_cat=catslug to admin menu
- Link to Second Level Admin Page
- How do I insert the smaller variant of an image?
- Why add_menu_page adds admin.php and how to remove it?
- Is there any way to add absolute path for add_menu_page function?
- Admin menu bar dropdown opens when I click on a form element (Chrome) [closed]
- how can i add custom menu in admin panel?
- Admin page repeatable fields
- Change URL of plugin admin menu
- menu_order not working with slugs that start with admin.php
- How to add_menu_page include a php file page from theme directory
- Removing posts and comments from WordPress
- Is it possible to pass variables from add_user_page?
- place a direct link to custom-stylesheet, under appearance menu in wp-admin
- Wrong current class on admin menu with add_submenu_page()
- How to access $menu variable in custom .PHP file that loads wp-load.php?
- Adding a submenu to the Tools menu returns tools.php in a popup box
- WordPress admin menu formatting issue
- What action/filter/function determines “current” class in WP Admin Menu
- ‘Headers already sent’ Error When Redirecting from add_submenu_page() Callback
- What’s the correct way of moving a menu page to a submenu
- Is it possible to add 3 level menu item to admin menu?
- Use Drag & Drop Functionality from WordPress Admin Area in the Frontend?
- Adding admin top-level menus
- Disordered sidebar in admin panel of self-hosted blog network [duplicate]
- How to rename Profile link in wp-admin page
- Additional menu item popping in submenus
- toolbar not visible on pages using front-page template
- Visiting a console submenu page does not expand its parent menu item
- Disable new Site Health screen safely?
- Remove Elementor Menu From WordPress Admin
- add submenu page doesn’t display
- Moving the WordPress dashboard avatar over the admin menu
- WordPress plugins add parent menu option in admin main right
- Change menu order of core post-type in UI?
- Margin problem on management menu?
- How can I move Customizer menu item to first level in WP Dashboard?
- How do I disable certain menu in editor user administrator page
- How can I restrict a custom WordPress role access to only a specific plugin?
- How can I reorder admin bar items?
- Admin sidebar customization
- Show limited menu to admin
- How would one add a nonce to a menu item in the WordPress dashboard?
- How can I change the admin menu title and url title on WordPress
- add sub_menu to a sub_menu (multiLevel sub_menu) in admin menu in wordpress
- add_menu_page not show link for custom role
- Linked pages not working with wordpress
- Hide admin menu items if it is empty
- Unable to add custom page to WordPress admin panel
- Insert link in sub menu – Admin panel
- How to add a notification next to custom admin menu?
- How to have submenus collapsed until they are clicked?
- admin menu: use default “general” page for theme settings using add_menu_page and add_submenu_page
- How to redirect one admin URL to another when admin page URL has “/admin.php?page=” in it?
- how to remove wp admin menu created by plugin
- How to check an admin submenu already exists?
- Renaming post to something else, breaks dashboard if edit_posts is false
- Removing admin menu items with white spaces
- Tab order of post admin page
- How can I modify text in admin bar?
- How to include the admin bar?
- Remove the theme info from main dashboard screen- not appearance
- How to add admin bar only page?
- Hiding an added admin page menu using css
- Turn on again old expandable menu
- How to create editable menu with parent and child in wordpress?
- How can I style my theme admin page?
- How to unset adminmenu completely?
- Responsive Admin Themes
- Add items to the dark menu in WordPress
- Adding admin link to Appearance via admin_menu, adds link to theme details modal