Back to Community

Troubleshooting Common CMB2 Metabox Display Issues: Why Your Box Isn't Showing

41 threads Sep 16, 2025 PluginCmb2

Content

If you've integrated the powerful CMB2 library into your WordPress site to create custom metaboxes, only to find they're not appearing where you expect, you're not alone. This is one of the most common hurdles developers face. Based on community discussions and solutions, let's explore why this happens and how to fix it.

Why Your CMB2 Metabox Might Not Appear

Several configuration issues can prevent a metabox from displaying. The good news is that most are simple to diagnose and resolve.

1. Incorrect `object_types` Parameter

The most frequent cause is an incorrect object_types parameter when initializing your metabox. This parameter tells CMB2 which WordPress editor screens should display the box.

Problem Example: A user reported their basic metabox code wasn't working. The issue was often traced back to this parameter not matching the intended post type, page, or screen.

Solution: Double-check that the 'object_types' array in your new_cmb2_box() call contains the correct values. For a post, it's 'post'. For a page, it's 'page'. For a user profile, it's 'user'. For a custom post type, use its exact slug.

// Correctly defining object_types for a page
$cmb = new_cmb2_box( array(
    'id'            => 'test_metabox',
    'title'         => __( 'Test Metabox', 'cmb2' ),
    'object_types'  => array( 'page' ), // This MUST be correct
    // ... other parameters
) );

2. Conditional Display with `show_on_cb`

Sometimes, you only want a metabox to appear under specific conditions, like for a particular page or user role. Using the show_on_cb (show on callback) parameter is the correct way to handle this.

Problem Example: A developer tried to disable CMB2 on the front-end by removing its init action with is_single(), which is not the intended method and won't work.

Solution: Use the 'show_on_cb' parameter to provide a callback function that returns true (show the box) or false (hide the box). This is the method recommended by the CMB2 team.

// Using a callback to conditionally show a metabox
$cmb = new_cmb2_box( array(
    'id'            => 'conditional_metabox',
    'title'         => __( 'Conditional Metabox', 'cmb2' ),
    'object_types'  => array( 'page' ),
    'show_on_cb'    => 'my_show_on_callback_function', // Your custom function
) );

// Define the callback function
function my_show_on_callback_function( $cmb ) {
    // Your logic here. Return true to show, false to hide.
    return get_the_ID() === 42; // Example: Only show on page ID 42
}

The CMB2 Snippet Library has numerous examples of conditional display logic you can adapt.

3. Hook Priority and Execution Order

WordPress hooks execute in a specific order. If your code runs before the post type is registered or before a parent theme's CMB2 code, it can cause problems.

Problem Example: A user with a child theme couldn't see their metabox because the parent theme's code, which defined the metabox they were trying to modify, hadn't run yet.

Solution: Ensure your CMB2 code runs at the appropriate time. The standard hook is cmb2_admin_init. If you need to remove or modify a metabox created by another plugin or theme, you may need to use a later priority (a higher number) on the same hook to ensure your code runs *after* the original metabox is created.

// Run your function later to ensure another metabox exists first
add_action( 'cmb2_admin_init', 'my_modification_function', 20 ); // Higher priority

Summary and Next Steps

If your CMB2 metabox is missing, walk through this checklist:

  1. Verify object_types: Is it set to the correct post type, user, or option page?
  2. Check for conditional callbacks: Are you using show_on_cb? If so, test the logic in your callback function to ensure it returns true when expected.
  3. Review hook priority: If modifying existing boxes, is your code running after the original is set up?

For further reading, the official CMB2 example functions file is an invaluable resource packed with commented examples of proper configuration.

By methodically checking these common areas, you can usually pinpoint and resolve the issue, getting your custom metaboxes to display perfectly.

Related Support Threads Support