With the code that you’ve added to your question, you’re adding the HTML ‘checked’ attribute twice, which is probably why things are getting confused. You have it hard-coded as checked="checked"
, but then checked( 1, get_option( 'theme_custom_option' ), false )
will write another checked attribute corresponding to the actual value of the option.
You should be able to verify this would have been able to debug it by looking at the generated HTML with view-source or developer tools.
Taken from the docs page for the checked
function in WordPress https://developer.wordpress.org/reference/functions/checked/ your code should probably look something like this:
echo '<input type="checkbox" class="theme-custom-checkbox" name="theme_custom_option" value="1" ' ;
echo checked( 1, get_option( 'theme_custom_option' ), false );
echo ' />';
Note code tidied a bit for readability
Related Posts:
- How to add custom css file in theme?
- get_template_part vs action hooks in themes
- How to remove search bar from a wordpress theme? [closed]
- Get url of thumbnail from the media uploader
- My child theme doesn’t work Error: “The parent theme is missing. Please install your parent theme”
- Should I use set_transient or update_option?
- Theme file for all pages that are a child of a specific page
- Template for individual post designs
- Best practice way to implement custom sections into a WordPress theme
- How to show next Post Thumbnail image in WordPress using current post id
- Pushing updates to your premium theme
- Where can I find a good reviewed collection of Twenty Ten child themes?
- Front End Post Submit Form
- How do I remove RSS feeds from themes?
- CSS in child theme not overriding the parent theme [closed]
- Advantages of using instead of wp_enqueue_style()?
- Style.css redirects to 404 Page not found
- Displaying wp menus by name without using theme locations
- How to add dynamic inline style?
- Optimal solution to develop a wordpress theme?
- How to add suggest plugin to theme?
- Create a theme by combining a parent and a child theme
- Prevent update check for specific theme
- How to add oEmbed support to my theme?
- Do I really need the div class entry?
- Am I supposed to create a child theme for every theme I use?
- using wordpress without javascript
- Theme Check: Could not find post_class
- Why wp_head() function not loading style.css?
- Override theme programmatically
- Set multiple templates per post
- How can I let templates choose which stylesheets are enqueued?
- WP 3.1 upgrade breaks AutoFocus+ theme
- How can I display/hide certain content based on a Theme Option field?
- create-guten-block in wordpress theme?
- How can I make that when I clic on one of the menu items, that page shows only posts with the same category?
- Theme Splash Image within the “Appearance -> Themes” control panel [duplicate]
- Theme Loading Into Dashboard
- How to make theme elements customizable in wordpress?
- Where to hook settings api init
- How to add “Template” option in page attributes panel?
- Which html elements should be styled in wordpress theme
- Folder name for a pro version of a WordPress.org theme?
- Customizer – loading settings/controls/sections/panels based on a id/page id
- Admin: sub menu doesnt display under apperance when activate my themes
- How can I change the theme of different posts using a plugin?
- Create a child theme from multiple themes
- Change image size depending on page
- Are seven additional image sizes are too many?
- How can I use the WordPress Loop and Pagination in multiple instances but different scenarios throughout my site?
- registering a global template wordpress 6.0
- Copying the theme style files and images to duplicate the website but with a difference
- Why still output /wp-content/themes/twentynineteen?
- I have WordPress setup on primary domain, how do I set it up on its subdomain using the same database?
- How to set Post meta-box defaults based on the choices made by user in Customizer?
- Theme Action to hook for one time only function [duplicate]
- get_header action not working
- How do I include a partial from a directory below a wordpress theme directory?
- Some doubts about WordPress handle the horizontal main menu visualization
- first excerpt fine, subsequent post excerpts shift to the right instead of displaying vertically [closed]
- HTTP Error when uploading images over specific dimensions
- Why is the `if else` not working?
- showing all recent posts in theme
- Tabbed theme options query about add_settings_section callback function
- iPad WordPress theme?
- custom Background not showing after upgrade?
- Rolling your own WordPress Themes
- List categories of a post hierarchically?
- How do I restructure the comment HTML layout?
- How to register dynamic settings in WordPress Customizer?
- PHP Parse error: syntax error, unexpected ‘endwhile’ (T_ENDWHILE), expecting elseif (T_ELSEIF) or else (T_ELSE) or endif (T_ENDIF) on line 124
- Theme: dropdown hover menu not showing up in IE/Edge
- Problem with pagination link (error 404)
- how to ensure responsiveness in wp themes? [closed]
- home is not working in wordpreess
- Is there a way to create sections under “Colors” panel in the Theme Customizer?
- Local theme changes upload on server but theme changes not showing
- WordPress Custom font not found
- WordPress uploads do not show up and I see the white screen of death in some cases
- Any way to permanently translate themes?
- New created Theme leads to malfunctioning Xampp Apache –> functions.php is cause
- WordPress Blog Page displaying nothing
- Primary Menu Showing All Pages With No Sub-Nav
- Magnific Popup – Add Caption to Images
- Why do WordPress developers use so many opening and closing PHP tags when developing themes? [duplicate]
- Safe way to echo wp_trim_words
- Theme Development : License help
- How can I demonstrate themes well?
- How to update my own theme?
- WordPress custom jquery not found
- Custom link color or stylesheets
- Showcase your wordpress themes [closed]
- How to remove proudly created by WordPress in theme?
- Roll my own theme or customize an existing one [closed]
- Why do some sites show themes/”themename” as the only theme?
- Meaning of “if ( is_home() && ! is_front_page() )” snippet?
- Dynamic nav menu with icons [closed]
- TItle In Latest Post is not using H1 Tag [closed]
- Is via.placeholder.com a good site to auto-generate placeholder images?
- Should we escape the values of constants?