Sillybean

Adding fields to existing options pages

There are lots of tutorials on adding a whole new options page for your plugin, but adding just a field or two to one of the standard options pages is a little different.

<br />
function add_extra_privacy_options() {<br />
     add_settings_field('extra_privacy', 'Extra Privacy Option', 'extra_privacy_options', 'privacy', $section = 'default', $args = array());<br />
     register_setting('privacy', 'extra_privacy');<br />
}</p>
<p>add_action('admin_init', 'add_extra_privacy_options');<br />
     // displays the options page content<br />
     function extra_privacy_options() { ?></p>
<input name='extra_privacy' value='<?php echo get_option('extra_privacy'); ?>' /><br />
<?php<br />
}<br />

The first argument in the register_setting() function is the one that identifies which existing page you want to use.

The new field on the Privacy settings page

That’s all you have to do! Just replace the form fields with your own. You’re using the Settings API, so your option will be saved and updated for you (as ‘extra_privacy’ in the wp_options table).

Posted on June 17, 2010 at 9:17 am in WordPress · 1 comment

Sharing this post? The short URL is: http://sillybean.net/?p=5251

One Response to “Adding fields to existing options pages”

  1. weston says:

    AWESOME! I was just thinking about this the other day. I didn’t want to create my own options panel, just add it on to a current one. Awesome!

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>