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.
do_meta_boxes action
Fires once for each of the default meta box contexts: normal, advanced, and side.
To use do_meta_boxes action, first you have to register it using add_action. You can write this code into functions.php of your activated theme or in a custom WordPress Plugin.
We at WePlugins always prefer to create a custom WordPress Plugin while using hooks so nothing breaks when you update your WordPress Theme in the future.
In the below live example, we have defined a function execute_on_do_meta_boxes_event which takes 3 parameters and we registered it using add_action. The first parameter do_meta_boxes is the name of the hook, the second parameter execute_on_do_meta_boxes_event is the name of the function which needs to be called, the third parameter is the priority of calling the hook if the same hook is used multiple times and the last parameter is the number of arguments (if any) to be passed in the registered function.
Sometimes, you have to remove a registered hook so you can use remove_action to remove the do_meta_boxes action.
Parameters
Below are the 3 parameters required to use this hook.
- $post_type : (string) Post type of the post on Edit Post screen, ‘link’ on Edit Link screen, ‘dashboard’ on Dashboard screen.
- $context : (string) Meta box context. Possible values include ‘normal’, ‘advanced’, ‘side’.
- $post : (WP_Post|object|string) Post object on Edit Post screen, link object on Edit Link screen, an empty string on Dashboard screen.
Live Examples
Example 1: Basic Usage of do_meta_boxes
Below is an example of how you can use this hook.
function weplugins_execute_on_do_meta_boxes_event($post_type, $context, $post){ // Code to be executed when this action occurs in WordPress. } // Add the action add_action( "do_meta_boxes", "weplugins_execute_on_do_meta_boxes_event" , 10, 3);
Example 2: Removing a Hook Callback
To remove a hook callback, use the example below.
remove_action( "do_meta_boxes", "weplugins_execute_on_do_meta_boxes_event", 10, 3 );
Please make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.
Example 3: Custom Functionality on do_meta_boxes
Implementing custom functionality based on the context and post type.
function weplugins_custom_meta_boxes($post_type, $context, $post) { if ($post_type == 'post' && $context == 'advanced') { // Custom code for advanced context in post type. } } // Add the action add_action( "do_meta_boxes", "weplugins_custom_meta_boxes", 10, 3 );
Contact Us
If you need customization or are having any trouble using this hook, please contact us and we’d be happy to assist you.
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.