4

Using WordPress Settings API tutorial I created a new custom menu and corresponding sub menus. Each of my menus have a page of its own. I used add_menu_page() and add_submenu_page() for that. (Here is the Complete Code)

Admin--------
» Special Admin
» Price Quotation

Now I'm trying to make a Plugin for some additional purposes. I want to integrate my plugin with the custom menu, I created earlier.

I placed a checkbox saying "Activate Price Quotation" in the "Special Admin" page. When the user Activates the Price Quotation the plugin will come into action. Then plugin will be available in the "Price Quotation" submenu_page.

There I'll make some tabbed pages under the Price Quotation page with some certain functionalities.

I tried with a basic plugin with add_plugins_page():

<?php
/*
 * Plugin Name: Price Quotation
 * Plugin URI: http://www.example.com
 * Author: Mayeenul Islam
 * Author URI: http://www.example.com
 * Version: 1.0.0
 */
?>

<?php

function add_a_menu(){
    add_plugins_page(
        'Price Factor',
        'Price Factor',
        'edit_posts',
        'edit_private_posts',
        'price_factor_callback'
    );
}
add_action('admin_menu', 'add_a_menu');

function price_factor_callback(){
    echo "This is Price Quotation Page";
}

?>

But this admin_menu filter added the menu under the default "Plugins" menu by default. How can I manage to call the menu or menus where I decided them to?

1 Answer 1

7

Use add_submenu_page instead.

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

$parent_slug should be one of the following

For Dashboard: add_submenu_page( 'index.php', ... ); Also see add_dashboard_page()
For Posts: add_submenu_page( 'edit.php', ... ); Also see Also see add_posts_page()
For Media: add_submenu_page( 'upload.php', ... ); Also see add_media_page()
For Links: add_submenu_page( 'link-manager.php', ... ); Also see add_links_page()
For Pages: add_submenu_page( 'edit.php?post_type=page', ... ); Also see add_pages_page()
For Comments: add_submenu_page( 'edit-comments.php', ... ); Also see add_comments_page()
For Custom Post Types: add_submenu_page( 'edit.php?post_type=your_post_type', ... );
For Appearance: add_submenu_page( 'themes.php', ... ); Also see add_theme_page()
For Plugins: add_submenu_page( 'plugins.php', ... ); Also see add_plugins_page()
For Users: add_submenu_page( 'users.php', ... ); Also see add_users_page()
For Tools: add_submenu_page( 'tools.php', ... ); Also see add_management_page()
For Settings: add_submenu_page( 'options-general.php', ... ); Also see add_options_page()

Example:

add_submenu_page( 'tools.php', 'My Custom Submenu Page', 'My Custom Submenu Page', 'manage_options', 'my-custom-submenu-page', 'my_custom_submenu_page_callback' ); 
3
  • Thanks for the answer. It's fine and working. I mentioned in my question, that I want to add the page under the custom menu page I added, suppose "Admin". So I added nano_admin into the $parent_slug, but it replaces my nano admin (referring to the Pastebin code). And also not making any new page, but generating a 404. Commented Oct 1, 2013 at 7:54
  • 1
    @MayeenulIslam I checked your pastebin code. Everything looks fine. I'm not really sure why its not working. Try again by renaming your slug. Commented Oct 1, 2013 at 18:01
  • It's OK. Thanks. I'll proceed with the other ways. May be some unknown conflict. :( Commented Oct 2, 2013 at 2:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.