Skip to content

Instantly share code, notes, and snippets.

@stefanbc
Created February 26, 2014 08:58
Show Gist options
  • Save stefanbc/9226102 to your computer and use it in GitHub Desktop.
Save stefanbc/9226102 to your computer and use it in GitHub Desktop.
Add Checkbox option to General Settings
<?php
$new_general_setting = new new_general_setting();
class new_general_setting {
function new_general_setting( ) {
add_filter( 'admin_init' , array( &$this , 'register_fields' ) );
}
function register_fields() {
register_setting( 'general', 'OPTION_NAME', 'esc_attr' );
add_settings_field('OPTION_NAME', '<label for="OPTION_NAME">'.__('OPTION_LABEL_TEXT' , 'OPTION_NAME' ).'</label>' , array(&$this, 'fields_html') , 'general' );
}
function fields_html() {
echo '<input type="checkbox" id="OPTION_NAME" name="OPTION_NAME" value="1" ' . checked(1, get_option('OPTION_NAME'), false) . '/>';
}
}
?>
@morgyface
Copy link

Hey Stefan, this is great, but, do you know how to choose where the checkbox option sits on the page. For example how would I make it appear between New User Default Role and Timezone?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment