How to get a slug name for a page without creating an admin page menu

I now use the add_submenu_page() function, but I don’t want the edit page to appear in the admin menu.

I want to access the edit page from a list (another page) directly. But I need the slug as a hook_suffix.

Read More

I have in my-edit.php

/* Set up the administration functionality. */
add_action( 'admin_menu', 'my_edit_setup' );

function my_edit_setup() {
...
/* Add Edit Actionlist page. */
$myplugin->my_edit = add_submenu_page( 'myplugin', esc_attr__( 'Edit', 'myplugin' ), esc_attr__( 'Edit', 'myplugin' ), 7, 'my-edit', 'my_edit' );
...

In admin.php I have:

function my_admin_enqueue_style( $hook_suffix ) {

  $pages = array(
    'admin_page_projects',
        '...my-edit'
  );

  if ( in_array( $hook_suffix, $pages ) ) {
    wp_enqueue_style( 'myplugin-admin', trailingslashit( MYPLUGIN_URI ) . 'css/admin.css', false, '20110525', 'screen' );

You see I need the $hook_suffix, but I can’t find out how to get this, without creating the admin menu item.

Related posts

Leave a Reply

1 comment

  1. Example of how to create an invisible sub menu (it gets attached to the Dashboard, index.php) and the correspondent $hook_suffix.

    The page can be accessed through http://example.com/wp-admin/index.php?page=sample_page_hidden.

    add_action(  'admin_menu', 'admin_menu_so_11593510' );
    add_action( 'admin_enqueue_scripts', 'admin_enqueue_scripts_so_11593510' );
    
    function admin_menu_so_11593510() 
    {
        add_submenu_page(
            null, // doesn't shows up in the menu, submenu is attached to "index.php"
            'Test', 
            'Test', 
            'edit_pages', 
            'sample_page_hidden', 
            'menu_options_so_11593510'
        );
    }
    
    function menu_options_so_11593510() { echo 'Hello!'; }
    
    function admin_enqueue_scripts_so_11593510( $hook_suffix )
    {
        if ( 'dashboard_page_sample_page_hidden' == $hook_suffix ) {
            wp_enqueue_script( 'swfobject' );
        }
    }