Set the ‘input’ to ‘html’ and write out the html for the input:
function filter_attachment_fields_to_edit( $form_fields, $post ) {
$foo = (bool) get_post_meta($post->ID, 'foo', true);
$form_fields['foo'] = array(
'label' => 'Is Foo',
'input' => 'html',
'html' => '<label for="attachments-'.$post->ID.'-foo"> '.
'<input type="checkbox" id="attachments-'.$post->ID.'-foo" name="attachments['.$post->ID.'][foo]" value="1"'.($foo ? ' checked="checked"' : '').' /> Yes</label> ',
'value' => $foo,
'helps' => 'Check for yes'
);
return $form_fields;
}
Saving works just as you did above, but you’re checking against a checkbox value instead, so you’ll need to update to true if isset() and update to false if not.
Related Posts:
- Change loop order via form or link (jquery, not URL)
- Why is unfiltered html allowed in custom fields for author / contributor roles?
- Using the theme options to change background
- wp_editor() usage in custom meta box
- Custom Field returning Numerical Value for Image rather than URL
- Custom post fields
- How do I Add images uploaded in the post to a default custom field
- Custom Field created in add_meta_boxes reappearing itself again in the default Custom Metabox
- How do you replace content generated by custom fields with custom blocks in Block Editor?
- Sort wp_query by sum of two meta fields
- What’s the best practice way of handling custom fields in different post formats?
- Custom page template with custom fields
- Where WordPress Stores The Custom Fields Values
- What is the best way to build home pages with a lot of sections for distributable themes [closed]
- How to add post meta fields to an article’s as meta elements
- Injecting pre-defined text from custom page template to editor
- Let user to add input fields on theme option page
- Get attachment meta (I need attachment ID, unsure how to find it)
- How to use shortcode inside of shortcode in theme
- Add image URL automatically to custom field?
- How can I add a field for featured image on backend of a custom Taxonomy?
- How to fix a conflict cause by my theme with Woocommerce and/or Gravity Forms?
- I want to change the author name
- Make a custom field in admin post.php read only
- How to add custom field option with menu?
- Add custom field to existing meta box?
- Add Field To All Pages
- How to detect mobile devices and present them a specific theme?
- Using wp_add_inline_style without a stylesheet
- Does the functions.php file ever get called during an AJAX call? Debug AJAX
- Bestway To Define Theme and Plugin path and url
- Hide a div that is part of all pages on one specific page
- Editing the custom background CSS
- How to force Media manager to overwrite files of same name?
- What is a good way to pass a variable from add_action to a Theme?
- Why does my short code get executed before other content?
- Enabling Widgets By Default in Custom Theme Development
- What are WooCommerce starter themes? [closed]
- How to disable the gradient and font size internal CSS added by WordPress when using theme.json
- Modifying JS files in Child-theme
- How do I display the “Archives” widget layout (sidebar) in WordPress by ‘year’ then by ‘months’?
- Where is the correct place(s) in twentysixteen’s header.php to add a Google webfont?
- Flexible WordPress theme creation using themes
- How to support Lazy Loading Assets in a WordPress Theme?
- How can one update a theme on a live site without interruption?
- Wysiwyg editor for P2 theme
- Toggle Sidebar Display
- How to move the the_excerpt’s read more link to another div
- Change The Meta-Description Of Home-Page?
- Limit Loop to 5 Posts?
- Add, edit specific CPT with custom role
- how to display search term in the template full site editor
- Table of Contents Before first heading
- How to add new page to wordpress theme through coding?
- comment form args are not translatable (customized comment form)
- Zoom on custom theme without child
- Changing a slider to a grid [closed]
- What do with the index.php … [duplicate]
- Question regarding WP multisite feature
- Code to determine WP version check
- “Theme without sidebar.php is deprecated”
- Is it acceptable for a WordPress theme to not accept widgets?
- get_term_link is Ending to single.php
- wp e-commerce – theme problem – why won’t it load wpsc-single_product.php? [closed]
- Extending Twenty Eleven Theme
- my excerpts lack the ‘more’ link
- Simple child theme modification but links are broken
- Iris color picker in custom theme option page not saving value
- Is functions.php in themes applied to all templates?
- Want to add cart and a search bar in the right of logo line
- how do i develop a global nav and local nav to be wordpress dynamic?
- Why Tags don’t appear in my page?
- First post full width without Sidebar
- How to make a theme unable to be used on a multisite network?
- How to determine when my theme is deactivated?
- 1 post per category on homepage and counting those posts
- if (has_custom_menu())?
- Exclude parent categories from the_category() within the loop
- Ensure SQL changes carry over
- How to display custom field in product description?
- wordpress can’t find single-project page
- How can I set multi archive page template on same time for only one custom post type?
- Show Yoast SEO meta tags in Custom WordPress Templates (Theme)
- How to show some of category in wordpress
- using themename_the_custom_logo() in template-tags?
- How to make the media library searchable by image title
- WordPress doesn’t load css, image and js files after moving local installation folder
- Custom page template not showing on page creation
- How to get url image page the right way?
- Mobile view logo background colour in wordpress
- How To Customise WordPress Comment Submit Button?
- Next/Previous post navigation
- page.php is not called when I load a Page
- Main Menu Theme Different Output Print
- How to reuse parts of WordPress site e.g. header, footer, part of header for multiple WordPress sites?
- How can I install my custom-made theme on a wordpress.com blog? [closed]
- IS there any reason not to include javascript in my own post’s embeds?
- How to create more templates to the same theme?
- A problem in loading index.php
- .submenu class missing in output from wp_nav_menu