36

add_options_page() automatically adds it underneath settings, however add_submenu_page() gives you control as to where you want it to show up. Try something like this: add_submenu_page( 'edit.php?post_type=portfolios', __( 'Test Settings', 'menu-test' ), __( 'Test Settings', 'menu-test' ), 'manage_options', 'testsettings', '...


27

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', ...


20

You can use the fourth parameter of add_menu_page(), the my_unique_slug, to check if the page exists: if ( empty ( $GLOBALS['admin_page_hooks']['my_unique_slug'] ) ) add_menu_page( 'Page Title', 'Top Menu Title', 'manage_options', 'my_unique_slug', 'my_magic_function' ); $GLOBALS['admin_page_hooks'] is the ...


12

This is an old post but can't you just use wordpress $menu and/or $submenu globals like Oleg suggested in number 2. When in doubt copy WordPress: wordpress/wp-admin/menu.php For example to add link this seems like it would work: function add_external_link_admin_submenu() { global $submenu; $permalink = admin_url( 'edit-tags.php' ).'?taxonomy=...


11

Use a submenu page as parent slug. The admin menu has just two levels, so the imaginary third level will be hidden. Sample code, tested: add_action( 'admin_menu', 'wpse_73622_register_hidden_page' ); function wpse_73622_register_hidden_page() { add_submenu_page( 'options-writing.php', 'Hidden!', 'Hidden!', 'exists', ...


10

For the custom link into the admin menu, you need to pick up a top-level menu item by its slug and register the function using the admin_menu action hook. Here is the list of Main Admin Menu slugs. index.php => Dashboard edit.php => Posts upload.php => Media link-manager.php => Links edit.php?post_type=page => Pages edit-comments.php => ...


8

Make sure that your add_action hook is set to admin_menu. Here's a sample code: add_action('admin_menu', 'wpse149688'); function wpse149688(){ add_menu_page( 'Wholesale Pricing', 'Wholesale', 'manage_options', 'woo-wholesale', 'woo_wholesale_page_call'); add_submenu_page( 'woo-wholesale', 'Registrations', 'Registrations', 'manage_options', 'woo-...


6

The WordPress functions changed since the answers here in 2014. As of today (Version 4.6.1) this code will create a main menu named "My Menu" , main item and sub item. To run code just paste and saves in your functions.php file in your child theme. $menu_id = wp_create_nav_menu('My Menu'); $parent_item = wp_update_nav_menu_item($menu_id, 0, array( '...


6

make the slug of parent menu item and sub menu same (first one item) like below function actions_recent_bids_add_admin_page(){ add_menu_page('Recent Bids', 'Auction Reports', 'manage_options','wc-auction-reports','actions_recent_bids_list','dashicons-chart-area', 56); add_submenu_page( 'wc-auction-reports', // parent slug 'Recent ...


4

It would go like this (note the absence of the function parameter - and also the capability instead of a role). add_action( 'admin_menu', 'wpse_74421_menu_admin' ); function wpse_74421_menu_admin() { add_submenu_page( 'edit.php?post_type=events', 'Add Gallery', 'Add Gallery', 'delete_plugins', 'admin.php?...


4

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 )...


4

To expand on @Jai example... My Settings $postType = 'foo'; $categoryType = 'bar'; Custom Post Type $args = array( 'labels' => array('name'=>$postType, ...), 'rewrite' => array('slug' => 'all-'.$postType), 'taxonomies' => array($...


4

add_submenu_page('edit.php?post_type='.$this->plugin->posttype, __('Settings', $this->plugin->name), __('Settings', $this->plugin->name), 'manage_options', $this->plugin->name, array(&$this, 'adminPanel')); there is admin panel is a callback function name.


4

This is the code I'm using, it's a custom nav walker for BootStrap but you could easily adapt it to your own. By the way, you could copy & paste my nav walker and be sure to change this line: $class_names .= ' dropdown'; to $class_names .= ' sub-menu'; Hope this helps. /** * Custom Bootstrap Nav Walker */ class macho_bootstrap_walker extends ...


3

I made the same mistake as the OP as it is not intuitive how to get this working. By reading the codex on Administration Menus, I discovered the answer. The problem (for me, anyway) was to edit the $parent_slug parameter in the call to add_submenu_page(...). So, in the OP's case, you would change: add_submenu_page( 'woo-wholesale', '...


3

Don't try to do this with admin menus/ admin pages. It is going to be a headache. Set up an AJAX API callback and you can have complete control of the output with no worries about any other markup since there won't be any. function download_xml_wpse_144156() { // generate your XML and echo it die(); } add_action('wp_ajax_grab_my_xml', '...


3

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', $...


3

You'd have to manipulate the global $submenu and modify the link in it. Or use jQuery. The following example adds a submenu in the Dashboard menu and changes the destination link just after. The submenu page will dump the contents of the global var. add_action( 'admin_menu', function() { add_submenu_page( 'index.php', ...


3

/** * Adds a submenu page under a custom post type parent. */ function books_register_ref_page() { add_submenu_page( 'edit.php?post_type=book', __( 'Books Shortcode Reference', 'textdomain' ), __( 'Shortcode Reference', 'textdomain' ), 'manage_options', 'books-shortcode-ref', 'books_ref_page_callback' );...


3

The setting API, which its usage is being demonstrated in that code is meant to be use as a framework to create settings pages which result in update of values in options. Widget settings are is a somewhat more abstract level. They are stored in options, but there is no flexibility how they are stored, they are all stored as array of mostly constant fields ...


2

I don't recommend you do that. Let's assume your prefix for admin.php is _trigger_me_ Submenu <?php function _clean_url_to_repalce_admin_menu($url, $original_url, $_context){ if ($url == 'admin.php?page=_trigger_me_'){ remove_filter('clean_url', '_clean_url_to_repalce_admin_menu', 10); //return admin_url('someotherpage.php); ...


2

I think you'll have to hook an earlier action and check if your subpage is being loaded, when the function to render the subpage happens it's too late to send headers. Your subpage's rendering function could just be blank because the earlier action would override it. I tried this with a subpage of themes.php and it seemed like it would work: function ...


2

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 my_add_submenu()...


2

Insert the URL of the page as the $menu_slug argument. Also note that user levels are deprecated, you should pass a capability instead. function add_custom_link() { add_submenu_page( 'edit.php?post_type=cpt_custom', '', 'Pending Posts', 'edit_posts', 'edit.php?post_type=cpt_custom&post_status=pending', ...


2

Try something like this: in the load hook, you can ouput your xml code. u function my_menu_pages() { $hook = add_submenu_page( null, 'Page Title', 'Page Title', 'administrator', 'sub-menu-slug', function() { } ); add_action('load-' . $hook, function() { // add your xml code here, // you will get a blank page ...


2

add_submenu_page() and similar functions accept a capability. Capabilities are slightly confusing in WordPress as every role name is a cap as well. So instead of just adding a role name, you could just take a capability that is shared between the roles of the Subscribers and the Editors. As you can see from the capabilities and roles table in Codex, read ...


2

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 ...


2

Ok, so I got annoyed with it not working and decided to just rewrite it. I'm not sure what the solution was, but I suspect two things: the wrong endpoint for the form (should be options.php) and the wrong $option_group and $option_name (they were probably not matched correctly). For posterity, I'll leave my rewrite here and hopefully it helps others. A few ...


2

For your particular situation, where you need to have a menu registered, but not shown unless you click on it from a link on another page you can add a conditional check to see if you're on the editing page. If so, then change replace null with book per the add_submenu_page() parameters. add_action( 'admin_menu', 'add_the_menus' ); function add_the_menus() {...


2

You need a way of managing your settings. You can use whatever methods of management as you see fit. However, I've came up with a fairly "simple" Settings PHP Class, which you can use to retrieve your Plugin's Settings as an Object with Properties. The Object is your Plugin's Settings. The Properties of the Object are what contain the actual settings ...


Only top voted, non community-wiki answers of a minimum length are eligible