Posts

Showing posts with the label Admin Menu

Wordpress - Add A Separator To The Admin Menu?

Answer : Here's a quick and dirty way to get what you want. Background WordPress stores admin menu sections in a global array called $menu . To add a separator you add an element to the $menu array using an index that is between the indexes of the options that you want to separate. Using the add_admin_menu_separator() function So I've written a function to encapsulate the logic for this I called add_admin_menu_separator() . You'll need to pick an array index number that is higher than the option after which you want to add a separator, and then call the function add_admin_menu_separator() passing said index as your parameter. For example: add_admin_menu_separator(37); The add_admin_menu_separator() function itself Here's the definition of the function add_admin_menu_separator() which you can copy into your theme's functions.php file. Yes it is arcane but then so is the code that creates and uses the global $menu array. (Plans are to eventu...

Wordpress - Add An Admin Page, But Don't Show It On The Admin Menu

Answer : From the docs on add_submenu_page() , you see that you can hide your submenu link from a top level menu item to which it belongs be setting the slug (1st argument) to null : add_action( 'admin_menu', 'register_my_custom_submenu_page' ); function register_my_custom_submenu_page() { add_submenu_page( null, 'My Custom Submenu Page', 'My Custom Submenu Page', 'manage_options', 'my-custom-submenu-page', 'my_custom_submenu_page_callback', ); } To highlight the desired menu item (e.g. 'all charts' when accessing the hidden 'edit chart' page), you can do the following: add_filter( 'submenu_file', function($submenu_file){ $screen = get_current_screen(); if($screen->id === 'id-of-page-to-hide'){ $submenu_file = 'id-of-page-to-higlight'; } return $submenu_file; }); Use a submenu page as parent slug...