Meta Box is simply a custom block of data that can be embedded in a webpage in WordPress. WordPress is equipped with an add_meta_box function for the purpose of creating custom meta boxes. The prototype for this function is illustrated below:
<? php add_meta_box($id, $title, $callback, $page, $context, $priority, $callback_args); ?>
It is essential to explain the parameters which are entered in the function prototype:
$id – It is the HTML ID of the meta box that you are going to introduce.
$title – This is quite simply the text displayed at the top of a meta box.
$callback- This attribute is used to render information in the created meta box.
$page – This refers to the target location of the meta box i.e. which webpage you want the meta
box displayed on.
$context – This indicates the location of meta box within the chosen webpage. ‘normal’ would
place it below the post editor, ‘side’ to editing screens right sidebar and ‘advanced’
puts the box in post editor’s column, but at a slightly lower level.
$priority – This variable places the meta box closer to the top, in its normal position or near the
bottom on entering ‘high’, ‘default’ or ‘low’ respectively.
$callback_args – This allows you to pass data in form of an array to the $callback function.
The question which arises now is where exactly is this function to be placed? The ideal place to insert this code is a plug-in file, because a plug-in file is independent of the webpage’s front end design.
Thus we see that the method to create a meta box is pretty simple. However, there is one precaution which we must strictly bear in mind while inserting the add_meta_box function – directly introducing the discussed code in a plug-in file will lead to an error because add_meta_box function will be called before WordPress was loaded.
To avoid this, we must wrap add_meta_box call in another function, and then hook that function into the add_meta_boxes action hook, which is a part of the plug-in API.