This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
When working with WordPress, hooks are a vital part of customizing and extending the functionality of your website. One such hook is the hidden_meta_boxes filter. This filter is used to control the list of hidden meta boxes on the WordPress admin screens. Let’s dive into how you can utilize this hook effectively.
Example 1: Modifying Hidden Meta Boxes
In this example, we’ll see how to modify the default hidden meta boxes. The function weplugins_modify_hidden_meta_boxes_defaults
is created to adjust the array of hidden meta boxes.
function weplugins_modify_hidden_meta_boxes_defaults($hidden, $screen, $use_defaults) { // Update the $hidden variable according to your website requirements and return this variable. return $hidden; } // add the filter add_filter( "hidden_meta_boxes", "weplugins_modify_hidden_meta_boxes_defaults", 10, 3 );
Example 2: Removing a Hook Callback
If you need to remove an existing hook callback, you can do so using the remove_filter
function. This is useful when you want to stop a specific function from modifying the hidden meta boxes.
remove_filter( "hidden_meta_boxes", "weplugins_modify_hidden_meta_boxes_defaults", 10, 3 );
Example 3: Conditional Modification of Meta Boxes
Here’s an example where the hidden meta boxes are modified conditionally based on the current screen.
function weplugins_conditional_hidden_meta_boxes($hidden, $screen, $use_defaults) { if ($screen->id == 'post') { // Modify $hidden for post screen } return $hidden; } add_filter( "hidden_meta_boxes", "weplugins_conditional_hidden_meta_boxes", 10, 3 );
Remember, using hooks like hidden_meta_boxes allows you to customize your WordPress site without altering core files, ensuring your changes remain intact during updates.
Contact Us if you need any customization or help with WordPress hooks. Visit our contact page for further assistance.
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.