Stephanie Leary

Writer and WordPress consultant

  • Books
    • Content Strategy for WordPress (2015)
    • WordPress for Web Developers (2013)
    • Beginning WordPress 3 (2010)
  • Blog
    • Fascism Watch (2016-17)
    • Content Modeling for WordPress series
    • WordPress Hidden Gems series
  • Work
    • Portfolio
    • Services
    • WordPress Plugins
    • WordPress Themes
    • Presentations and Interviews
    • on GitHub →
  • About
    • Press Kit
  • Contact
    • Mailing List

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

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 *

Fascism Watch

The Fascism Watch is a daily(ish) news roundup. View all the previous Fascism Watch posts »

Latest WordPress Book

Content Strategy for WordPress

A short book for content strategists and managers on implementing a complete content strategy in WordPress: evaluation, analysis, content modeling, editing and workflows, and long-term planning and maintenance.

Read the sample chapter

Kindle Nook iBooks Kobo Smashwords

WordPress for Web Developers

WordPress for Web Developers (9781430258667)

This is a book for professional web designers and developers who already know HTML and CSS, and want to learn to build sites with WordPress. The book begins with a detailed tour of the administration screens and settings, then digs into server-side topics like performance and security. The second half of the book is devoted to development: learning to build WordPress themes and plugins.

This is the second, much-revised and updated edition of Beginning WordPress 3, with a more accurate title. Everything’s been updated for WordPress 3.6.

WordPress for Web Developers is out now. See what's inside...

The best WordPress features you’ve never noticed

  • WordPress Hidden Gems: Screen Options
  • WordPress Hidden Gems: Bulk Edit
  • WordPress Hidden Gems: Private Status
  • WordPress Hidden Gems: Dashboard Feed Readers
  • WordPress Hidden Gems: Options.php

Content Modeling for WordPress series

  • Content modeling for WordPress, part 1: analyze content
  • Content modeling for WordPress, part 2: functional and organizational requirements
  • Content modeling for WordPress, part 3: a sample content model

This is an excerpt from Content Strategy for WordPress.My latest books are Content Strategy for WordPress (2015) and WordPress for Web Developers (2013). Sign up to be notified when I have a new book for you.

Copyright © 2021 Stephanie Leary