• Skip to primary navigation
  • Skip to main content
  • Skip to footer
  • Books
    • Content Strategy for WordPress (2015)
    • WordPress for Web Developers (2013)
    • Beginning WordPress 3 (2010)
  • Blog
    • Content Modeling for WordPress
    • WordPress Hidden Gems
    • Web Design
  • Work
    • MLIS Class Projects (2019-2022)
    • Portfolio (2002-2019)
    • Services
    • WordPress Plugins
    • WordPress Themes
    • Presentations and Interviews
    • on GitHub →

Stephanie Leary

Writer, WordPress consultant, recent MLIS grad

  • About
    • Press Kit
    • Presentations and Interviews
  • Contact Me

Adding pages to all the WordPress submenus

June 4, 2010 Stephanie Leary 2 Comments

Most WordPress plugin tutorials tell you to add your option pages to the Settings submenu, and that’s that. Did you know that add_options_page() isn’t your only choice?

Here are the functions to add pages to all the major submenus:

<br />
<?php<br />
//Settings<br />
add_options_page (page_title, menu_title, capability, handle);<br />
// Tools<br />
add_management_page (page_title, menu_title, capability, handle);<br />
// Appearance<br />
add_theme_page (page_title, menu_title, capability, handle);<br />
// Posts<br />
add_posts_page (page_title, menu_title, capability, handle);<br />
// Pages<br />
add_pages_page (page_title, menu_title, capability, handle);<br />
// Users<br />
add_users_page (page_title, menu_title, capability, handle);<br />
?><br />

The page_title is the text that will appear as the <title> and <h2> tags on your option page. The menu_title is the text that will appear as an item in the navigation menu — you might use a shorter phrase there. The capability is a relevant capability a user should have in order to do stuff with your plugin options. (It’s not the role, because lots of plugins modify the basic roles, so it’s safer to check for a specific capability.)

For example, if you’re creating a plugin that manages user roles and capabilities, you might call your option page Role Manager, and the function containing your the form markup might be ‘role_manager_plugin_options’. If you wanted to put the page under Users, you’d write the following:

<br />
// add the page to the navigation menu<br />
add_action('admin_menu', 'role_manager_plugin_add_page');</p>
<p>function role_manager_plugin_add_page() {<br />
   // Add a new submenu under Users:<br />
   add_users_page('Role Manager Options', 'Role Manager', 'edit_users', 'role_manager_plugin_options');<br />
}<br />

(Updated to correct add_user_page() to add_users_page(). Thanks, Ozh!)

This is part of the chapter on creating plugins in Beginning WordPress 3.

WordPress Plugins

Reader Interactions

Comments

  1. Ozh says

    June 10, 2010 at 9:51 am

    Hu… I hope this isn’t a copy/paste of what you actually put in your book because this is all wrong :)

    First, it’s not add_user_page() but add_users_page()

    Second, a parameter is missing, you need to define a slug for the page then a function that will output the page. Omitting the function parameter will cause WP to assume just including the file without calling any function will be enough to draw the menu, but this is just whacky to do it this way.

    Reply
    • steph says

      June 10, 2010 at 12:56 pm

      I’m pretty sure it’s in the book, but I’ll have to go check. I’m also certain that I got the functions straight out of the Codex.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Footer

My Books

I’m a front end developer at Equinox OLI, working on open source library software. I was previously a freelance WordPress developer in higher education. You can get in touch here or on LinkedIn.

Copyright © 2023 Stephanie Leary · Contact