Using WordPress ‘filter_block_editor_meta_boxes’ PHP filter

The filter_block_editor_meta_boxes WordPress PHP filter allows you to modify meta box data right before it’s rendered in the block editor.

Usage

add_filter('filter_block_editor_meta_boxes', 'your_custom_function');

function your_custom_function($wp_meta_boxes) {
    // your custom code here
    return $wp_meta_boxes;
}

Parameters

  • $wp_meta_boxes (array): The global meta box state containing all registered meta boxes.

More information

See WordPress Developer Resources: filter_block_editor_meta_boxes

Examples

Rearrange Meta Boxes Order

Rearrange the order of the meta boxes in the ‘side’ context.

add_filter('filter_block_editor_meta_boxes', 'rearrange_meta_boxes_order');
function rearrange_meta_boxes_order($wp_meta_boxes) {
    // Swap the order of two meta boxes
    $temp = $wp_meta_boxes['post']['side']['core']['custom_meta_box_1'];
    $wp_meta_boxes['post']['side']['core']['custom_meta_box_1'] = $wp_meta_boxes['post']['side']['core']['custom_meta_box_2'];
    $wp_meta_boxes['post']['side']['core']['custom_meta_box_2'] = $temp;

    return $wp_meta_boxes;
}

Remove a Meta Box

Remove a meta box with the ID ‘custom_meta_box’ from the ‘post’ post type.

add_filter('filter_block_editor_meta_boxes', 'remove_custom_meta_box');
function remove_custom_meta_box($wp_meta_boxes) {
    unset($wp_meta_boxes['post']['side']['core']['custom_meta_box']);
    return $wp_meta_boxes;
}

Move a Meta Box to a Different Context

Move the ‘custom_meta_box’ meta box from the ‘side’ context to the ‘normal’ context.

add_filter('filter_block_editor_meta_boxes', 'move_meta_box_context');
function move_meta_box_context($wp_meta_boxes) {
    $wp_meta_boxes['post']['normal']['core']['custom_meta_box'] = $wp_meta_boxes['post']['side']['core']['custom_meta_box'];
    unset($wp_meta_boxes['post']['side']['core']['custom_meta_box']);
    return $wp_meta_boxes;
}

Change Meta Box Priority

Change the priority of the ‘custom_meta_box’ meta box to ‘high’.

add_filter('filter_block_editor_meta_boxes', 'change_meta_box_priority');
function change_meta_box_priority($wp_meta_boxes) {
    $wp_meta_boxes['post']['side']['high']['custom_meta_box'] = $wp_meta_boxes['post']['side']['core']['custom_meta_box'];
    unset($wp_meta_boxes['post']['side']['core']['custom_meta_box']);
    return $wp_meta_boxes;
}

Modify Meta Box Data

Update the title of the ‘custom_meta_box’ meta box.

add_filter('filter_block_editor_meta_boxes', 'modify_meta_box_data');
function modify_meta_box_data($wp_meta_boxes) {
    $wp_meta_boxes['post']['side']['core']['custom_meta_box']['title'] = 'New Title';
    return $wp_meta_boxes;
}