Custom metaboxes are an incredibly powerful and useful part of the WordPress ecosystem. What are they and how can they be used? Let’s dive in!
The What & WHY
Custom metaboxes are stand alone boxes that can be added to the WordPress editor. They are a user interface for storing information attached to a post, called the postmeta. They are highly customizable and can be fairly easy to use. While you can use the built-in Custom Fields box in WordPress, and it can be advantageous at times, using your own custom metaboxes is often a better solution. They can be easier and more intuitive for anyone using the editor, and they are much more customizable than the Custom Fields box.
The How (Three Ways)
Easiest – Advanced Custom Fields
Advanced Custom Fields is a really handy plugin you can use to add custom metaboxes to your site. It is incredibly powerful, despite being fairly easy to start using.
- Easy to Use and Set Up
- Great Documentation
- They offer many paid and free add-ons
- You must purchase a license to unlock many of the advanced features
- The postmeta is stored in two rows in the database (an important consideration on large sites)
A Little More Technical – CMB2
CMB2 is a really useful tool that makes coding custom metaboxes a little less painful. Maintained by WebDevStudios, CMB2 lets developers build metaboxes without all of the code and settings required by a pure solution.
- Available in plugin form or as a bootstrap
- Great documentation and code examples on their GitHub repository
- You have to write code
- It is a toolkit, not a complete solution with a GUI
Down & Dirty With Code – WordPress API
Your first experience with writing your own custom metaboxes is likely to be filled with a lot of banging your head against a hard surface. But, like so many other WordPress APIs, after the first time you build it, it keeps getting significantly easier. Using built-in features is arguably the best route to go if you plan on distributing your WordPress project to others, as it is lightweight and writing the “WordPress” way usually means you are better setup for future-proofing.
- You have complete control
- The best solution for distributing your own plugins or themes
- This is the most amount of work out of the three