Custom Metaboxes — The How, What, and Why

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.

PROs
  • Easy to Use and Set Up
  • Great Documentation
  • They offer many paid and free add-ons
CONS
  • 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)
RESOURCES

https://www.advancedcustomfields.com/

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.

PROS
  • Available in plugin form or as a bootstrap
  • Great documentation and code examples on their GitHub repository
CONS
  • You have to write code
  • It is a toolkit, not a complete solution with a GUI
Resources

https://github.com/CMB2/CMB2

https://cmb2.io/

https://github.com/CMB2/CMB2-Snippet-Library

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.

PROS
  • You have complete control
  • The best solution for distributing your own plugins or themes
CONS
  • This is the most amount of work out of the three
RESOURCES

https://developer.wordpress.org/plugins/metadata/custom-meta-boxes/

One thought on “Custom Metaboxes — The How, What, and Why

Comments are closed.