4

I want to add a field to the general settings page, but I can not save the field because I can't find a hook for the pages save.

Any ideas?

1 Answer 1

6

You just need to register_setting() on your setting and it will be saved automatically. See the Settings API for more info. Here's a complete example:

function spw_cb() {
    if( !($value = get_option('sprockets_per_widget')) ) {
        $value = 7;
    }

    ?>
    <input type="text" size="3" name="sprockets_per_widget" value="<?php echo $value; ?>" /> Numeric only!
    <?php
}

function spw_init() {
    add_settings_field('sprockets_per_widget', 'Sprockets per Widget', 'spw_cb', 'general');
    register_setting('general', 'sprockets_per_widget', 'intval');
}
add_action('admin_init', 'spw_init');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.