Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use postbox_classes_screen_id_box_id filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
January 14, 2023
5 minutes read

Welcome to the detailed guide on the `postbox_classes_screen_id_box_id` filter hook in WordPress. Here, we’ll explore how to use this hook to filter the postbox classes for a specific screen and box ID combo. This hook is quite helpful if you’re looking to customize the classes applied to your postboxes in the WordPress admin panel.

Access Premium WordPress Plugins

postbox_classes_screen_id_box_id filter

Filters the postbox classes for a specific screen and box ID combo.

apply_filters( "postbox_classes_{$screen_id}_{$box_id}", string[] $classes )

Description

This filter hook filters the postbox classes for a specific screen and box ID combo. It consists of one parameter: `$classes`, an array of postbox classes. The dynamic portions of the hook name, `$screen_id` and `$box_id`, refer to the screen ID and meta box ID, respectively. This hook is used by `postbox_classes()` which returns the list of classes to be used by a meta box.

Parameters

  • $classes: (string[]) An array of postbox classes.

Live Examples

Adding a New Class to Postbox

In this example, we add a new class to the array of postbox classes.

add_filter('postbox_classes_screen_id_box_id', 'weplugins_add_metabox_classes');

function weplugins_add_metabox_classes($classes) {
    array_push($classes, 'another_class');
    return $classes;
}

Removing a Hook Callback

This example demonstrates how to remove a hook callback to stop adding the new class to postbox classes.

// remove the filter 
remove_filter('postbox_classes_screen_id_box_id', 'weplugins_add_metabox_classes', 10);

Modifying Existing Classes

Here, we modify the existing classes by appending a suffix to each class name.

add_filter('postbox_classes_screen_id_box_id', 'weplugins_modify_metabox_classes');

function weplugins_modify_metabox_classes($classes) {
    foreach ($classes as &$class) {
        $class .= '_modified';
    }
    return $classes;
}

Contact Us

If you need further customization, feel free to contact us.

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.