Adding an Options Page

First, add the options screen to the admin navigation menu, as shown in Listing 7-28.

Listing 7-28. Adding a theme options page to the admin menu function simplex_menu() {

add_theme_page('Simplex Flex Options', 'Simplex Options', 'edit_theme_options',

add_action('admin_menu', 'simplex_menu');

Actually, that's really all it takes! The simplex_menu() function will contain several other things in just a moment, but for now it holds only the add_theme_page() function. This function requires several arguments:

• The title of the options page, to be used in the <title> tag

• The title of the page as it will appear in the menu

• The capability users should have in order to access this page (see Chapter 10 for more on roles and capabilities); either edit_themes or manage_options would be a good choice for a theme options page.

• The path to the file containing the options page (in this case, it'll be this file)

• The name of the function containing the options form

Once that's done, you have to add your simplex_menu() function to the admin menu. There's an action hook for that, so all you have to do is call add_action().

Note that you haven't created the simplex_options_page() function yet. That's OK; the menu option will show up without it, and will take you to a blank page. Before you fill in the form, you need to think about what options your theme will have.

Was this article helpful?

0 0

Post a comment