How to add custom Metabox in WordPress without any Plugin?


In the following topic i will show how we can make a custom Metabox on our WordPress web site. It will help you to add that in your existing theme or plugin. I like to keep that straightforward avoiding packing virtually any unneeded scripts during my concept. Thus let us get going!

Suppose we have a custom post type as “Jokes Now we will add some extra metabox for that post type. There will have “Contributor NameContributor State, Contributor City as metabox. Let’s get started to do that.

Step 1 : Create the function to retrieve custom fields :

That function will return the custom metabox field value or as well as false in the event that there is no value injected. If you want you can add your own logical conditions there too.

Step 2 : Register the Metabox For Post types

Now you need to register your metabox in custom post type. You can also add that on wordpress default page, default post too.

You can change the function name, post type name, metabox information, priority ( high, low), Display area ( side, normal) etc.

Step 3: Metabox Output in Admin Area

If you want to add textarea at the place of input textfield, just put the <textarea></textarea> code there.

Step 4: Save the Metabox Data

Before saving any metabox value, the above function will check three things:

  •   When we doing autosave itt will stop running
  •   It will run only after a user action, no remote publishing by scripts.
  •   If user have permission doing wordpress post_edit then the function will work.

Preview :


I think now everybody can add custom metabox in wordpress without using any plugin.

NB : By following above method you can add text field, text area easily as custom meta box.


About Author

I have no more personal information to share with you but have enough experience to share with all. I am always funny