Adding a Section to an Existing Options Page

If you have just a few settings to work with and it would make sense to include them on an existing page rather than creating a whole new one, you can do so. For example, if you had an option related to privacy, you could use the code in Listing 9-29 to add your option to that page.

Listing 9-29. Adding an option to the Privacy page function add_extra_privacy_options() {

add_settings_field('extra_privacy', 'Extra Privacy Option', 'extra_privacy_options', 'privacy', $section = 'default', $args = array()); register_setting('privacy','extra_privacy');

add_action('admin_init', 'add_extra_privacy_options');

// displays the options page content function extra_privacy_options() { ?>

Keep in mind that the standard WordPress options pages are laid out using tables. The contents of your display function will appear inside a table cell. The results of Listing 9-29 are shown in Figure 9-9.

Figure 9-9. An extra option on the Privacy page

See for more examples of adding options pages to various parts of the admin menu.

0 0

Post a comment