SlideShare a Scribd company logo
1 of 36
Download to read offline
Make Meta
Boxes Great Again
Nate Allen
Senior WordPress Engineer at Linchpin
Twitter: ncallen
Github: nate-allen
https://linchpin.agency
Meta Boxes and Custom Fields
What’s the difference?
What are Custom
Meta Boxes?
function meta_box_example() {
add_meta_box(
'meta_box_example',
__( 'I'm a Custom Meta Box',
'meta_box_example' ),
'meta_box_example_html',
'post',
'normal',
'default'
);
}
add_action( 'add_meta_boxes',
'meta_box_example' );
What are Custom
Meta Boxes?
(Way more code than the basic
example!)
What are Custom
Fields?
Custom fields are a feature built into
WordPress
(Field names starting with an
underscore don’t show up here)
There has to be a better
way...
Advanced Custom Fields CMB2
Carbon Fields
CustomPress
Custom Field Suite
Easy Custom Fields
Fields FrameworkMeta Box
PapiPods Types
WP MetaboxerPiklist
WordPress Creation Kit
Ultimate CMS
MasterPress
Custom Content Type Manager
Advanced Custom Fields CMB2
Advanced Custom Fields:
Easily create beautiful and powerful
UI for entering custom field data
Text
Textarea
Checkbox
Radio Button
Select
True / False
File
Image
oEmbed
Wysiwyg Editor
Repeater
Gallery
Flexible Content
Clone
Options Page
Color Picker
Date Picker
Date Time Picker
Google Map
Time Picker
Tab
Page Link
Post Object
Relationship
Taxonomy
Free Pro
Repeater Field
The repeater field allows you to create a set
of sub fields which can be repeated again and
again.
Any type of field can be added as a sub field.
Great for things like slideshows, portfolios,
testimonials, and more.
Can help eliminate the need for some plugins
and custom post types.
Flexible Content Field
Similar to the repeater field, but
instead of 1 set of sub fields, you can
have an infinite set of sub field
groups (layouts).
Allows you to build modular websites
that are flexible, but also consistent.
My Personal Philosophy:
Give clients flexibility
without too much freedom
Other cool things you can do with ACF
● Extend ACF with your own fields:
https://github.com/elliotcondon/acf-field-type-template
● Add fields to more than just posts: Users, Attachments, Taxonomies,
Comments, and frontend forms.
● Use the built-in filters for more control.
● “Tabs” field allows you to organize fields better
ACF is Great! But...
1. It’s not easy to version
control...
Save field settings as JSON with ACF Pro!
● Simply create a new folder in your theme and
name it acf-json.
● Each field “group” will save as a separate JSON
file.
● Added benefit… fields load faster in WP-Admin!
2. Your clients can (and will)
mess with the field settings!
You have a couple
options...
Include the ACF files within your theme/plugin
● Code to do that here:
https://advancedcustomfields.com/resources/including-acf-in-a-plugin-theme
● This WILL cause issues if the client installs ACF...
● You could do a check to see if the plugin is installed first, and not include your
ACF files if it is. But that defeats the purpose.
Hide ACF in the admin menu
● Simply add this to your plugin/theme:
add_filter('acf/settings/show_admin', '__return_false');
● Or write a function that only shows it for specific people.
3. ACF Causes front end
dependency issues...
ACF encourages you to use its own functions to
retrieve data
● ACF documentation tells you to use get_field, the_field, get_sub_field,
etc
● If you disable the plugin, you will have issues. If you want to move away from
ACF, you will have to refactor.
● Field data can be retrieved with get_post_meta()
● But you will have to do a little more work to get the data in the format you
need.
4. You can’t include ACF Pro
in your free themes and
plugins...
Introducing:
CMB2
ACF vs CMB2
● Where ACF is user friendly, CMB2 is developer friendly.
● CMB2 is completely free! You can include it in your plugins and themes.
● Has a lot of the same fields as ACF, including a repeater. But no “flexible
content” field.
● Easy version control. Can include with Composer if that’s your thing…
● You use get_post_meta to get data… the way it should be!
Example: First, create a meta box...
$cmb = new_cmb2_box( array(
'id' => 'test_metabox',
'title' => __( 'Test Metabox', 'cmb2' ),
'object_types' => array( 'page', ), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
'cmb_styles' => false, // false to disable the CMB stylesheet
'closed' => true, // Keep the metabox closed by default
) );
Example: Next, add your fields!
$cmb->add_field( array(
'name' => 'Color Picker',
'id' => '_my_prefix_colorpicker',
'type' => 'colorpicker',
'default' => '#ffffff',
) );
$cmb->add_field( array(
'name' => 'oEmbed',
'desc' => 'Enter a youtube, twitter, or instagram URL.',
'id' => '_my_prefix_embed',
'type' => 'oembed',
) );
Results in this...
More info about CMB2 here:
https://github.com/WebDevStudios/CMB2
Any questions?

More Related Content

Similar to Make Meta Boxes Great Again

WordPress Custom Fields: Control your content presentation by breaking out of...
WordPress Custom Fields: Control your content presentation by breaking out of...WordPress Custom Fields: Control your content presentation by breaking out of...
WordPress Custom Fields: Control your content presentation by breaking out of...
Denise Williams
 
The Basic Concept Of IOC
The Basic Concept Of IOCThe Basic Concept Of IOC
The Basic Concept Of IOC
Carl Lu
 
Workshop: Creating your first WordPress plugin
Workshop: Creating your first WordPress pluginWorkshop: Creating your first WordPress plugin
Workshop: Creating your first WordPress plugin
ylefebvre
 
Dot Net Fundamentals
Dot Net FundamentalsDot Net Fundamentals
Dot Net Fundamentals
LiquidHub
 
Web technology practical list
Web technology practical listWeb technology practical list
Web technology practical list
desaipratu10
 

Similar to Make Meta Boxes Great Again (20)

Make Meta Boxes Great Again
Make Meta Boxes Great AgainMake Meta Boxes Great Again
Make Meta Boxes Great Again
 
WordPress Custom Fields: Control your content presentation by breaking out of...
WordPress Custom Fields: Control your content presentation by breaking out of...WordPress Custom Fields: Control your content presentation by breaking out of...
WordPress Custom Fields: Control your content presentation by breaking out of...
 
The Joy of Subforms with Randy Carey
The Joy of Subforms with Randy CareyThe Joy of Subforms with Randy Carey
The Joy of Subforms with Randy Carey
 
Wordcamp abq cf-cpt
Wordcamp abq cf-cptWordcamp abq cf-cpt
Wordcamp abq cf-cpt
 
Spencer Nash - Advanced Custom Fields
Spencer Nash - Advanced Custom FieldsSpencer Nash - Advanced Custom Fields
Spencer Nash - Advanced Custom Fields
 
Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)
Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)
Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress Websites
 
C#/.NET Little Wonders
C#/.NET Little WondersC#/.NET Little Wonders
C#/.NET Little Wonders
 
Engage - Expanding XPages with Bootstrap Plugins for ultimate usability
Engage - Expanding XPages with Bootstrap Plugins for ultimate usabilityEngage - Expanding XPages with Bootstrap Plugins for ultimate usability
Engage - Expanding XPages with Bootstrap Plugins for ultimate usability
 
14 asp.net session20
14 asp.net session2014 asp.net session20
14 asp.net session20
 
Do it in code! A guide to creating a custom site structure plugin in WordPress.
Do it in code! A guide to creating a custom site structure plugin in WordPress.Do it in code! A guide to creating a custom site structure plugin in WordPress.
Do it in code! A guide to creating a custom site structure plugin in WordPress.
 
AD301: Introducing the Composite Application Container Framework - Lotusphere...
AD301: Introducing the Composite Application Container Framework - Lotusphere...AD301: Introducing the Composite Application Container Framework - Lotusphere...
AD301: Introducing the Composite Application Container Framework - Lotusphere...
 
The Basic Concept Of IOC
The Basic Concept Of IOCThe Basic Concept Of IOC
The Basic Concept Of IOC
 
Workshop: Creating your first WordPress plugin
Workshop: Creating your first WordPress pluginWorkshop: Creating your first WordPress plugin
Workshop: Creating your first WordPress plugin
 
Learning .NET Attributes
Learning .NET AttributesLearning .NET Attributes
Learning .NET Attributes
 
Learn dot net attributes
Learn dot net attributesLearn dot net attributes
Learn dot net attributes
 
Productionalizing ML : Real Experience
Productionalizing ML : Real ExperienceProductionalizing ML : Real Experience
Productionalizing ML : Real Experience
 
Acquia Drupal Certification
Acquia Drupal CertificationAcquia Drupal Certification
Acquia Drupal Certification
 
Dot Net Fundamentals
Dot Net FundamentalsDot Net Fundamentals
Dot Net Fundamentals
 
Web technology practical list
Web technology practical listWeb technology practical list
Web technology practical list
 

Recently uploaded

Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Monica Sydney
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理
F
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Monica Sydney
 
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
ydyuyu
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
pxcywzqs
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
F
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
gajnagarg
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Monica Sydney
 
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
ayvbos
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
ydyuyu
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Monica Sydney
 

Recently uploaded (20)

Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
 
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
 
Call girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girlsCall girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girls
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
 
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime BalliaBallia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 

Make Meta Boxes Great Again

  • 2.
  • 3. Nate Allen Senior WordPress Engineer at Linchpin Twitter: ncallen Github: nate-allen https://linchpin.agency
  • 4. Meta Boxes and Custom Fields What’s the difference?
  • 5. What are Custom Meta Boxes? function meta_box_example() { add_meta_box( 'meta_box_example', __( 'I'm a Custom Meta Box', 'meta_box_example' ), 'meta_box_example_html', 'post', 'normal', 'default' ); } add_action( 'add_meta_boxes', 'meta_box_example' );
  • 6. What are Custom Meta Boxes? (Way more code than the basic example!)
  • 7. What are Custom Fields? Custom fields are a feature built into WordPress (Field names starting with an underscore don’t show up here)
  • 8. There has to be a better way...
  • 9. Advanced Custom Fields CMB2 Carbon Fields CustomPress Custom Field Suite Easy Custom Fields Fields FrameworkMeta Box PapiPods Types WP MetaboxerPiklist WordPress Creation Kit Ultimate CMS MasterPress Custom Content Type Manager
  • 11. Advanced Custom Fields: Easily create beautiful and powerful UI for entering custom field data
  • 12. Text Textarea Checkbox Radio Button Select True / False File Image oEmbed Wysiwyg Editor Repeater Gallery Flexible Content Clone Options Page Color Picker Date Picker Date Time Picker Google Map Time Picker Tab Page Link Post Object Relationship Taxonomy Free Pro
  • 13. Repeater Field The repeater field allows you to create a set of sub fields which can be repeated again and again. Any type of field can be added as a sub field. Great for things like slideshows, portfolios, testimonials, and more. Can help eliminate the need for some plugins and custom post types.
  • 14.
  • 15.
  • 16.
  • 17. Flexible Content Field Similar to the repeater field, but instead of 1 set of sub fields, you can have an infinite set of sub field groups (layouts). Allows you to build modular websites that are flexible, but also consistent.
  • 18. My Personal Philosophy: Give clients flexibility without too much freedom
  • 19.
  • 20. Other cool things you can do with ACF ● Extend ACF with your own fields: https://github.com/elliotcondon/acf-field-type-template ● Add fields to more than just posts: Users, Attachments, Taxonomies, Comments, and frontend forms. ● Use the built-in filters for more control. ● “Tabs” field allows you to organize fields better
  • 21. ACF is Great! But...
  • 22. 1. It’s not easy to version control...
  • 23. Save field settings as JSON with ACF Pro! ● Simply create a new folder in your theme and name it acf-json. ● Each field “group” will save as a separate JSON file. ● Added benefit… fields load faster in WP-Admin!
  • 24. 2. Your clients can (and will) mess with the field settings!
  • 25. You have a couple options...
  • 26. Include the ACF files within your theme/plugin ● Code to do that here: https://advancedcustomfields.com/resources/including-acf-in-a-plugin-theme ● This WILL cause issues if the client installs ACF... ● You could do a check to see if the plugin is installed first, and not include your ACF files if it is. But that defeats the purpose.
  • 27. Hide ACF in the admin menu ● Simply add this to your plugin/theme: add_filter('acf/settings/show_admin', '__return_false'); ● Or write a function that only shows it for specific people.
  • 28. 3. ACF Causes front end dependency issues...
  • 29. ACF encourages you to use its own functions to retrieve data ● ACF documentation tells you to use get_field, the_field, get_sub_field, etc ● If you disable the plugin, you will have issues. If you want to move away from ACF, you will have to refactor. ● Field data can be retrieved with get_post_meta() ● But you will have to do a little more work to get the data in the format you need.
  • 30. 4. You can’t include ACF Pro in your free themes and plugins...
  • 32. ACF vs CMB2 ● Where ACF is user friendly, CMB2 is developer friendly. ● CMB2 is completely free! You can include it in your plugins and themes. ● Has a lot of the same fields as ACF, including a repeater. But no “flexible content” field. ● Easy version control. Can include with Composer if that’s your thing… ● You use get_post_meta to get data… the way it should be!
  • 33. Example: First, create a meta box... $cmb = new_cmb2_box( array( 'id' => 'test_metabox', 'title' => __( 'Test Metabox', 'cmb2' ), 'object_types' => array( 'page', ), // Post type 'context' => 'normal', 'priority' => 'high', 'show_names' => true, // Show field names on the left 'cmb_styles' => false, // false to disable the CMB stylesheet 'closed' => true, // Keep the metabox closed by default ) );
  • 34. Example: Next, add your fields! $cmb->add_field( array( 'name' => 'Color Picker', 'id' => '_my_prefix_colorpicker', 'type' => 'colorpicker', 'default' => '#ffffff', ) ); $cmb->add_field( array( 'name' => 'oEmbed', 'desc' => 'Enter a youtube, twitter, or instagram URL.', 'id' => '_my_prefix_embed', 'type' => 'oembed', ) );
  • 35. Results in this... More info about CMB2 here: https://github.com/WebDevStudios/CMB2