How to add a WordPress admin page without adding it to the menu?

I am creating a WordPress plugin and I would like the editing page to be inaccessible through a submenu (because then the item will not be specified).

This resource (http://codex.wordpress.org/Adding_Administration_Menus) shows how to associate the admin page with a function, but not do it without adding it as a menu item.

Can this be done?

Thank!

+45
wordpress wordpress-plugin
Oct 11 '10 at 0:11
source share
11 answers

Yes, it can be done (well, technically, it will be more like registering all this and then deleting the menu item later), but it would be easier (I think) to check the parameters in $_GET super-global to indicate that the user wants to edit a specific item.

For example, you might have a page listing the items to edit, and clicking "edit" adds the item ID to the current URL (the query string).

In the function displaying this page, if an ID is defined, give them a page to edit this element.

Otherwise, give them a list view. How posts, pages, and other custom post types do it.

+13
Oct 11 2018-10-10
source share

The best solution here is http://wordpress.org/support/topic/add-backend-page-without-menu-item use add_submenu_page with parent slug = null

+60
Aug 05 2018-12-12T00:
source share

add_submenu_page with parent slug = null

OR

add_submenu_page with menu title = null

+9
Oct 06 '12 at 9:16
source share

Yes. It is very possible to make a page inaccessible through a submenu or even the main menu in the WP admin panel. See code snippet below.

 function myplugin_render_edit_page() { // Code contains the UI for edit page. } /** * Manage menu items and pages. */ function myplugin_register_admin_page() { global $_registered_pages; $menu_slug = plugin_basename('myplugin.php'); $hookname = get_plugin_page_hookname($menu_slug,''); if (!empty($hookname)) { add_action($hookname, 'myplugin_render_edit_page'); } $_registered_pages[$hookname] = true; } add_action('admin_menu', 'myplugin_register_admin_page'); 

Hope this helps.

+4
Apr 14 2018-11-21T00:
source share

Note. This solution does not automatically set the current menu and submenu item. If you want to highlight a specific menu as current when a hidden page is being viewed, see my other answer .

From the answers before me, you can see that there are many ways to do this. However, there is another way, which, in my opinion, may be better.

Loading a page in different ways depending on the value of the $_GET var request is one option, but maybe this is not what some people are looking for.

Suggestions regarding add_submenu_page() are on the right track, but each of the previous sentences has problems. Setting $menu_title to null prevents the menu item from being displayed, but simply makes the link not contain any text. The link still takes up some space on the menu, though, so it looks ridiculous. Setting $parent_slug to null does not have this problem, but I noticed that the HTML title page does not display the text $page_title .

My solution was to set $parent_slug to a fake menu pool like 'i_dont_exist' . The menu item will not be displayed, and when viewing the administrator screen, the page title will be filled correctly.

 add_submenu_page( '_doesnt_exist' ,__( 'Page title', 'textdomain' ) ,'' ,'manage_options' ,'menu_slug' ,'display_my_menu' ); 
+4
Jan 07 '14 at
source share

use this code to create a new page without adding to the menu

 add_action( 'admin_menu', 'register_newpage' ); function register_newpage(){ add_menu_page($appname, $appname, 'administrator','custompage', 'custom'); remove_menu_page('custom'); } function custom() { echo "hai"; } 
+3
Mar 26 '14 at 10:44
source share

I tried all the suggestions here, but with various problems associated with each.

WordPress code for add_submenu_page now gives the correct answer, which should use options.php as the parent pool. I tried a trick using the generated name, but which gives permission errors that use the same zero in different places, either makes the menu text just be absent (but still available for click), or for the name of the browser that is missing.

Using options.php worked, and I did not see any problems as a result of using it.

+1
May 13 '15 at 13:12
source share

One of the problems that I discovered by simply adding null as the parent pool for the submenu item is that if you are currently viewing this particular page, then the submenu will not be displayed (at least it is not for me (along with with the page title that does not appear).

What I did was add an empty span element inside the menu title and use jquery to move the parent elements and hide it.

0
Feb 24 '15 at 12:25
source share

Using add_submenu_page with a NULL parent definitely works, however, if you want to keep an unlinked page associated with a specific menu (for example, a custom menu such as a message), you should use @Boopathi's response variation:

 function my_hidden_submenu_page(){ //add the submenu page the usual way add_submenu_page('edit.php?post_type=custom-type', 'My Page Title', 'My Page Title', 'manage_options', 'my-page-slug', 'my_page_callback'); //then remove it remove_submenu_page('edit.php?post_type=custom-type','my-page-slug'); } add_action('admin_menu', 'my_hidden_submenu_page'); 

It seems that the two actions cancel each other out, however remove_submenu_page does not unregister the callback function; it just removes the link.

That way, when someone views your unrelated page, the correct navigation menu (our menu, such as user messages in this example) will still show as active.

0
Mar 16 '16 at 3:35
source share

Finally, I found a way to do this, which is not an ugly hack, does not require JS to highlight the desired menu item (and submenu item) and works for regular menus registered by plugins ( @Josh answer only works for custom message types).

Essentially, you just need to register your submenu in normal mode, but then connect to the 'submenu_file' filter to unregister it and, in addition, also set another element of the submenu to highlight.

 function so3902760_wp_admin_menu() { // Register the parent menu. add_menu_page( __( 'Parent title', 'textdomain' ) , __( 'Parent', 'textdomain' ) , 'manage_options' , 'my_parent_slug' , 'display_my_menu' ); // Register the hidden submenu. add_submenu_page( 'my_parent_slug' // Use the parent slug as usual. , __( 'Page title', 'textdomain' ) , '' , 'manage_options' , 'my_hidden_submenu' , 'display_my_submenu' ); } add_action( 'admin_menu', 'so3902760_wp_admin_menu' ); function so3902760_wp_admin_submenu_filter( $submenu_file ) { global $plugin_page; $hidden_submenus = array( 'my_hidden_submenu' => true, ); // Select another submenu item to highlight (optional). if ( $plugin_page && isset( $hidden_submenus[ $plugin_page ] ) ) { $submenu_file = 'submenu_to_highlight'; } // Hide the submenu. foreach ( $hidden_submenus as $submenu => $unused ) { remove_submenu_page( 'my_parent_slug', $submenu ); } return $submenu_file; } add_filter( 'submenu_file', 'so3902760_wp_admin_submenu_filter' ); 
0
Nov 30 '17 at 15:54
source share

I find that you can do this by reusing the insert id, for example:

 add_menu_page( 'User AS Packages', 'User AS', 'manage_options', 'myplugin/editaspackages.php', 'UserASPackages', '', 8); add_menu_page( 'User ARP Packages', 'User ARP', 'manage_options', 'myplugin/editarppackages.php', 'UserARPPackages', '', 8); add_menu_page( 'AS Packages', 'AS Packages', 'manage_options', 'myplugin/ars-s2.php', 'ARPPackages', '', 8); 

The last 3, using position 8, and the last, redefine the two before the two in front of them are displayed.

-one
Feb 24 '15 at 17:09
source share



All Articles