Codex tools: Log in
Contents |
Compares two given values (for example, a saved option vs. one chosen in a form) and, if the values are the same, adds the checked attribute to the current radio button or checkbox.
This is essentially the same as comparing values with if(), but results in more concise code.
Testing the value with if():
<input type='checkbox' name='options[postlink]' value='1' <?php if ( 1 == $options['postlink'] ) echo 'checked="checked"'; ?> />
Using checked() instead:
<input type="checkbox" name="options[postlink]" value="1" <?php checked( $options['postlink'], 1 ); ?> />
Since: 1.0
checked() is located in wp-includes/general-template.php.