How to include custom meta box field in WordPress Screen Options panel

I’m working on a WordPress site where I built a custom meta box using CMB2 framework. This meta box contains a field named product_code that I created for my custom taxonomy.

I want to make this custom field appear in the Screen Options dropdown so users can toggle its visibility on and off. Is there a way to add custom meta box fields to the WordPress Screen Options menu?

Here’s a simple example of what I’m trying to achieve:

function register_custom_metabox() {
    $metabox = new_cmb2_box(array(
        'id' => 'item_details_box',
        'title' => 'Item Information',
        'object_types' => array('product')
    ));
    
    $metabox->add_field(array(
        'name' => 'Product Code',
        'id' => 'product_code',
        'type' => 'text'
    ));
}

Any guidance would be appreciated.

hey! u gotta use the screen_option hook with the add_meta_boxes_screen filter. when registering ur CMB2 box, set show_on_cb param, then hook into add_screen_option to make it toggleable. its tricky but doable with some custom code.

CMB2 doesn’t work with screen options out of the box. Just add a checkbox to your metabox header and use some jQuery to toggle field visibility. Way easier than fighting with WordPress core hooks.

Been there - manual coding for this gets messy fast.

WordPress Screen Options wasn’t built for granular field control. You’ll end up writing custom JavaScript, hooking into multiple filters, and maintaining code that breaks with updates.

I solved this by automating the whole visibility system. Instead of fighting WordPress limitations, I built a workflow that monitors user interactions and automatically shows/hides fields based on behavior patterns and preferences.

The automation tracks which fields users actually use, stores preferences, and dynamically adjusts the interface. No Screen Options headaches or complex CMB2 callbacks.

It handles bulk updates when you need to change visibility settings across multiple users or post types. Way cleaner than writing custom PHP hooks for every field.

Best part - set it up once and it handles all future custom fields automatically. No more coding the same visibility logic repeatedly.

Check out how to build this automation at https://latenode.com

WordPress Screen Options wasn’t built for dynamic field management. All these solutions need constant maintenance and break with every update.

I hit this same wall managing product fields across multiple sites. Instead of fighting CMB2 hooks and Screen Options, I automated the whole thing.

Built a workflow that watches how users interact with fields and auto-adjusts visibility by role. It learns which fields actually get used and hides the rest - no manual Screen Options needed.

Handles bulk changes across all custom post types and taxonomies. New fields? It applies the learned patterns automatically instead of making users hunt through menus again.

Beats writing PHP callbacks for every field or splitting metaboxes to work around WordPress quirks. Set it up once and it manages visibility based on real usage data.

Screen Options handles entire metaboxes, not individual fields. WordPress doesn’t let you toggle CMB2 fields one by one through Screen Options - you’d need heavy customization for that. Better approach: use CMB2’s show_on_cb parameter to control field visibility, or add some JavaScript that shows/hides fields based on user preferences saved in user meta. Another option is splitting your metabox into smaller ones. Each small metabox becomes a Screen Options toggle, giving users more control without the complex coding.

You need to use WordPress’s native metabox system instead of CMB2 directly. Had the same problem last year on a client project. Here’s what works: register your metabox with WordPress’s add_meta_box() function first, then put CMB2 inside that container. Hook into the add_meta_boxes action and use add_meta_box() with the right parameters - especially callback_args for Screen Options to work. In your callback function, just render the CMB2 fields like normal. Screen Options will see it as a regular WordPress metabox and let users toggle it. Set your context parameter to ‘normal’, ‘side’, or ‘advanced’. This way you keep all CMB2’s functionality but WordPress treats it like any other metabox.

Screen Options only sees metaboxes registered through WordPress core functions. CMB2 skips this system completely, so your metabox won’t show up there automatically. Had the same problem last year building a custom product manager. Fix is to register a wrapper metabox with add_meta_box() first, then hook CMB2 into that container. You’ll modify your registration function to use WordPress’s native metabox registration, then call your CMB2 fields from the callback. Basically trick WordPress into thinking it’s a standard metabox while keeping CMB2’s functionality. Works with Screen Options and doesn’t break CMB2’s features.