WordPress Add Admin Submenu Page

vicnumb Nov 19, 2012

Nov 19 2012 Published by under Word Press

Most WordPress plugin manuals explain how to add pages linked to admin menu. A few lines and you have a new page. Same page appears in your WordPress blog menu.

Sometimes it is necessary to add submenu pages that are not linked directly to your WordPress admin menu.

 

Say you run a directory of some items, and need sub-menu pages to add/edit these items, display some details or do some operations. These submenu pages have no sense without their parent directory page and all should be linked to it, but not to wordpress admin menu.

 

Adding WordPress sub-menu admin page

 
<?php add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function ); ?>

To add the WordPress Admin area page without linking it to admin menu, replace the variable $parent_slug by values null

Variable explanation
* $parent_slug – admin menu item new page is linked to
* $page_title – new page title tag content
* $menu_title – new page admin menu name
* $capability – what type of wordpress blog users may see this page
* $menu_slug – new page file name or variable name (e.g. menu slug = menu_slug, the url defining this page is ?page=menu_slug)
* $function – function called on loading the new page

 

Example:

<?php
 
add_action('admin_menu', 'setup_extramenu_page');
 
function setup_extramenu_page() {
    add_submenu_page( null, 'Extra Menu Page', 'Extra Menu Page', 'Administrator', 'extramenu-page', 'extramanu_page_function' ); 
}
 
function extramanu_page_function() {
    ?>
    <h2>Extra Menu Page</h2>';
    <?php
}
 
?>

To link to this page from another page use the url like, including the menu slug as page identification
http://yourblog.com/wp-admin/?page=extramenu-page

 

For more information read the WordPress official documentation.

No responses yet

Leave a Reply