Just set the name attribute in your checkbox tag in the format like: favourite_colors[]. The following code is derived from this thread.
add_settings_field(
'favourite-colors',
'Select your favourite colour',
'favourite_colors_checkbox_callback',
'my-settings'
);
function favourite_colors_checkbox_callback() {
$options = get_option( 'favourite_colors' );
$html="<input type="checkbox" id="red" name="favourite_colors[red]" value="1"" . checked( 1, $options['red'], false ) . '/>';
$html .= '<label for="red">Red</label><br />';
$html="<input type="checkbox" id="yellow" name="favourite_colors[yellow]" value="1"" . checked( 1, $options['yellow'], false ) . '/>';
$html .= '<label for="yellow">Yellow</label>';
echo $html;
}
Related Posts:
- How to get the Date Format and Time Format settings for use in my template?
- Custom editor field displaying HTML in Visual editor
- On Install, which code sets the ‘home’ option?
- How to use get_option() without any filter?
- Custom widget select options needs to stay selected after save
- Include user defined styles without including wp-load
- Warning: Creating default object… when altering Customize panels
- WordPress slugs and 404 handling takes preference over folders in site root?
- What changes we need to make to a theme so it can be installed as a MU Theme?
- How do I make mysite.com/comingsoon WordPress to become my main website’s WordPress?
- How to add the option to choose between sizes for featured image within post editor?
- Edit a custom admin page
- Custom options – register, defaults and delete empty fields (Settings API)
- How to delete orphan userdata from array in wp-options
- retrieve theme custom settings
- Looking for a lightweight theme using WP3 new tags and features (not 2010) [closed]
- What is the best way to customise admin files so they survive future upgrades?
- Verify nonce in REST API?
- Creating my own Admin Forms in a WordPress CMS?
- How To Provide Sub-Blogs Their Own Domain Names?
- Custom taxonomy: same terms, but for different years
- Best practices for A/B testing?
- Editing the Number at the end of Page URLs / Editing Page Slugs
- Automatic image renaming based on title
- Can I use $wpdb for my custom tables in the WordPress database?
- How to get input_attrs in the sanitize function?
- Integrating MailChimp newsletters as post
- What is WordPress file encoding?
- Change from /wp-admin/ to something else?
- WP_Query with the “offset” argument
- Adding “Interesting Tags” & “Ignored Tags” like StackOverflow.com in a WordPress Blog?
- Auto add taxonomy if post has category
- Add a containing DIV to core Gutenberg blocks
- Allow comments without approval for custom content type
- Add ‘Right Now’ widget to custom dashboard
- Are there any security issues with setting the WP_INSTALLING constant to true?
- Naming script handles right way
- How to edit pages after installing WP
- Exclude custom taxonomy tag from loop
- User Roles Not Sticking
- Login form in popup
- Multiple WordPress outside wordPress installation?
- WordPress generated links – menus and home_url() – not using https despite settings
- WordPress custom login page
- How to use
- Get page ID outside the loop, matching menu ID
- Gallery IDS and Captions: hide/show on a per ID basis
- How to check if a custom user profile field is empty
- Properly customizing login/register form
- Author Tracking Code!
- Change the Labels of Users to Customers in Admin
- Show Featured Post Only On The Homepage
- How can I create a second multisite network in a subdirectory?
- Choose sidebars column in widgets.php page [closed]
- order event posts by multiple custom fields
- How can I create a permalink with two categories, with the order based on the parent category?
- How do I add a promotional message to my posts?
- Customize option – add two image uploader under same section
- Modify the display Text of number of comments
- Toggle custom fields?
- Simplify the admin end
- Creating a shortcode by pulling in a custom field from a plugin
- Divi: how to hide/show specific menu according current page?
- “woocommerce_form_field()” function having issues after latest woocommerce update [closed]
- Hide Customizer’s Widget Choices From The List
- How to add span on WordPress Title for first and third word
- Custom Post Types database persistance. Why not?
- Edit specific text on a static page
- Customise the Category Widget
- Showing Meta Box via Jquery Checkbox
- custom user meta query
- Problem with custom function from jQuery slider tutorial
- SELECT field options disappear when saving widget
- Create new network instance, import old single installs AND keep the urls?
- Don’t update modify time post on Quick Edit
- Style WooCommerce Product Search Widget
- Problems with setting up a subdomain to serve images and scripts
- Why does a custom php code inside a custom template not get executed?
- Change login cookie expiration time?
- Disable “-mp4-image” screenshots from appearing in Media?
- wordpress custom posts page not showing
- Wrap WordPress Login Form in custom Div
- Automatically reject a comment if website field contains anything
- Post filter with multiple checkbox taxonomy terms
- Replace publish date in blog module with custom field
- Need help with drop down list on the profile
- Hosing a website within a WordPress directory/folder
- Custom Single Template
- how to auto fille conatct form 7 when user is logined
- Creating WordPress staging environment software
- How to add H1 Tag on Homepage?
- Use another theme template in my theme
- Display popular posts by how many hits it got within 30 days of publishing
- Pulling posts into static site (wordpress as subdirectory)
- Call a duplicate registration form with other url
- Theme Options Menu Item – Permission Issue
- Setting variables as custom field values
- Which IDE best for WordPress Development? [closed]
- How do I fix the url when clicking on portfolio item?
- Particle.js not loading in WordPress Gutenberg