WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can you please let me know how I can add a checkbox to Setting API in creating Custom Options Page? I am using the following code to add a txt box which is working perfectly but I am totally confused how to add chechbox to the setting API and options. I just tried ti update the input type to checkbox but I am not sure what to put in Value besides when I save the form the check box still appears unchecked!

                    'Display Paragraph:',

 public function the_option_label_setting()
       echo "<input name='My_Theme_Options[the_option_label]' type='text' value='{$this->options['the_option_label']}'/>";


share|improve this question
up vote 3 down vote accepted

Have a look at: The Complete Guide To The WordPress Settings API (Part 8: Validation, Sanitisation, and Input II):

    'Checkbox Element',  
    'Checkbox Element',  

function sandbox_checkbox_element_callback() {

    $options = get_option( 'sandbox_theme_input_examples' );

    $html = '<input type="checkbox" id="checkbox_example" name="sandbox_theme_input_examples[checkbox_example]" value="1"' . checked( 1, $options['checkbox_example'], false ) . '/>';
    $html .= '<label for="checkbox_example">This is an example of a checkbox</label>';

    echo $html;


EDIT: Check box fields do not use the value attribute to determine if the box is checked. They use a checked attribute. The $html line above has been edited using the code from later in the article referenced above. Read the articles for details.

share|improve this answer
Hi Till Thanks for your comment I tried your hint and the code from the link but I am still having some issues here! The problem is when I checked the checkbox and save the options the new page is still unchecked! I mean it is not reading the data from the Options! Can you please let me know how to do this ? I know in Text box we can use the value='{$this->options['the_option_label']} but how about the checkbox? – Mona Coder Aug 18 '13 at 5:41
Edited Till's answer with corrected code from the article. – Charles Clarkson Aug 18 '13 at 6:12
Thanks Charles, – Mona Coder Aug 18 '13 at 6:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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