Directory / plugin

Categories Metabox Enhanced

v0.9.2 · by Yoren Chang

Replace the checkboxes with radio buttons or a select drop-down in the built-in Categories metabox and the Block Editor sidebar panel.

About this plugin

Try it live in your browser — launch the WordPress Playground demo. Boots a WordPress instance with this plugin active, the Category taxonomy pre-configured as radio buttons, and seeded posts you can edit in the Block Editor or run through Quick Edit / Bulk Edit immediately.

Thanks to Taxonomy_Single_Term, a library created by WebDevStudios, it made my work much easier on creating this plugin.

With Categories Metabox Enhanced, you can:

  • Change the built-in Categories metabox/panel to a single term UI, which means replacing the checkboxes with radio buttons or a select drop-down.
  • Apply the single term UI to other hierarchical taxonomies from the plugin’s Settings page.
  • Configure each hierarchical taxonomy independently — the same install can keep one taxonomy as checkboxes while another is forced to radio.
  • Customize the single term UI by setting these options:
    • Option type (checkbox, radio, or select).
    • Priority and position (context) of the metabox placement. Classic editor only.
    • Title of the metabox / Block Editor panel.
    • Whether child-terms should be indented.
    • Whether adding new terms from the metabox is enabled.
    • Whether a term selection is required (Force selection). When on, the classic metabox hides the “None” option, the Block Editor sidebar drops the “— Select —” entry once a term is chosen, and an empty save is substituted with a default term server-side so REST and programmatic callers can’t bypass it.

The single-term invariant is enforced everywhere posts can be saved: the Classic Editor metabox, the Block Editor sidebar panel, Quick Edit, Bulk Edit, the REST API, WP-CLI, and any code that calls wp_set_object_terms() directly. The classic-editor and Block Editor surfaces enforce in the UI; everything else is enforced on the server via the set_object_terms action, which coerces multi-term submissions to the last term and substitutes the default term on empty submissions when Force selection is on.

The substituted default term resolves in this order: the default_<taxonomy> option (e.g. default_category) the default_term_<taxonomy> option populated by register_taxonomy() default_term arg (WP 5.5+) the first term ordered by name. Override per taxonomy with the of_cme_force_selection_default_term filter.

The Block Editor sidebar panel is rendered for taxonomies registered with show_in_rest = true. Hierarchical taxonomies that opt out of REST fall back to the Classic Editor metabox path.

Plugin tags