How to Create New Meta Box WordPress

A meta box in wordpress can do a lot of nice things because if you know how to use these structures you can improve your wordpress website without using any plugin. Using meta boxes you will be able to create a new structure (new administrable fields) in your posts or pages or even in your custom post types (in admin panel). In other words with meta boxes you can scale your wordpress theme to a new level.

New Meta Box Wordpress

To create a new meta box in wordpress we have to open functions.php and let's create our first meta box for default post in wordpress. Using the following line of code we will create a new input text in the Add new Post page, or Edit post.

add_meta_box('test', 'Test', 'my_content_function');

Normally the above function has more parameters but all we need to make the function work is this.

First parameter is $id, the second one is the Title and the third parameter is used for the callback. In my_content_function we will add all the content we want to show in our metabox.

function my_content_function(){
  $template = '<div class="meta_box_content">';
  $template .= '<input type="text" name="my_first_input", placeholder="Add Title here">';
  $template .= '</div>';	
  echo $template;
}

Now refresh any post you have or create a new one and you will see the field there. Let me know if you need any help with this implementation.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x