SlideShare a Scribd company logo
1 of 35
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

Wordcamp abq cf-cpt
Wordcamp abq cf-cptWordcamp abq cf-cpt
Wordcamp abq cf-cptmy easel
 
Learning .NET Attributes
Learning .NET AttributesLearning .NET Attributes
Learning .NET AttributesPooja Gaikwad
 
Learn dot net attributes
Learn dot net attributesLearn dot net attributes
Learn dot net attributessonia merchant
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress WebsitesKyle Cearley
 
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...Brian O'Gorman
 
14 asp.net session20
14 asp.net session2014 asp.net session20
14 asp.net session20Vivek chan
 
Learn about dot net attributes
Learn about dot net attributesLearn about dot net attributes
Learn about dot net attributessonia merchant
 
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 Careyjdaychi
 
A Dictionary Of Vb .Net
A Dictionary Of Vb .NetA Dictionary Of Vb .Net
A Dictionary Of Vb .NetLiquidHub
 
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.Peter Hebert
 
Writing your own WordPress themes and plugins
Writing your own WordPress themes and pluginsWriting your own WordPress themes and plugins
Writing your own WordPress themes and pluginsStephanie Wells
 
Web technology practical list
Web technology practical listWeb technology practical list
Web technology practical listdesaipratu10
 
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)Roman Zenner
 
PVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckPVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckAndrey Karpov
 
Murach: How to use Entity Framework EF Core
Murach: How to use Entity Framework EF  CoreMurach: How to use Entity Framework EF  Core
Murach: How to use Entity Framework EF CoreMahmoudOHassouna
 
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)Ranel Padon
 
Advanced Custom Fields: Amazing Possibilities and Irritating Limitations
Advanced Custom Fields: Amazing Possibilities and Irritating LimitationsAdvanced Custom Fields: Amazing Possibilities and Irritating Limitations
Advanced Custom Fields: Amazing Possibilities and Irritating LimitationsEast Bay WordPress Meetup
 

Similar to Make Meta Boxes Great Again (20)

Wordcamp abq cf-cpt
Wordcamp abq cf-cptWordcamp abq cf-cpt
Wordcamp abq cf-cpt
 
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
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress Websites
 
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...
 
14 asp.net session20
14 asp.net session2014 asp.net session20
14 asp.net session20
 
Learn about dot net attributes
Learn about dot net attributesLearn about dot net attributes
Learn about dot net attributes
 
C#/.NET Little Wonders
C#/.NET Little WondersC#/.NET Little Wonders
C#/.NET Little Wonders
 
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
 
A Dictionary Of Vb .Net
A Dictionary Of Vb .NetA Dictionary Of Vb .Net
A Dictionary Of Vb .Net
 
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.
 
Writing your own WordPress themes and plugins
Writing your own WordPress themes and pluginsWriting your own WordPress themes and plugins
Writing your own WordPress themes and plugins
 
Web technology practical list
Web technology practical listWeb technology practical list
Web technology practical list
 
Custom PrimeFaces components
Custom PrimeFaces componentsCustom PrimeFaces components
Custom PrimeFaces components
 
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)
 
PVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckPVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd Check
 
Murach: How to use Entity Framework EF Core
Murach: How to use Entity Framework EF  CoreMurach: How to use Entity Framework EF  Core
Murach: How to use Entity Framework EF Core
 
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
 
Advanced Custom Fields: Amazing Possibilities and Irritating Limitations
Advanced Custom Fields: Amazing Possibilities and Irritating LimitationsAdvanced Custom Fields: Amazing Possibilities and Irritating Limitations
Advanced Custom Fields: Amazing Possibilities and Irritating Limitations
 
C# features
C# featuresC# features
C# features
 

Recently uploaded

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 

Recently uploaded (20)

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

Make Meta Boxes Great Again

  • 2. Nate Allen Senior WordPress Engineer at Linchpin Twitter: ncallen Github: nate-allen https://linchpin.agency
  • 3. Meta Boxes and Custom Fields What’s the difference?
  • 4. 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' );
  • 5. What are Custom Meta Boxes? (Way more code than the basic example!)
  • 6. What are Custom Fields? Custom fields are a feature built into WordPress (Field names starting with an underscore don’t show up here)
  • 7. There has to be a better way...
  • 8. 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
  • 10. Advanced Custom Fields: Easily create beautiful and powerful UI for entering custom field data
  • 11. 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
  • 12. 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.
  • 13.
  • 14.
  • 15.
  • 16. 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.
  • 17. My Personal Philosophy: Give clients flexibility without too much freedom
  • 18.
  • 19. 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
  • 20. ACF is Great! But...
  • 21. 1. It’s not easy to version control...
  • 22. 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!
  • 23. 2. Your clients can (and will) mess with the field settings!
  • 24. You have a couple options...
  • 25. 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.
  • 26. 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.
  • 27. 3. ACF Causes front end dependency issues...
  • 28. 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.
  • 29. 4. You can’t include ACF Pro in your free themes and plugins...
  • 31. 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!
  • 32. 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 ) );
  • 33. 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', ) );
  • 34. Results in this... More info about CMB2 here: https://github.com/WebDevStudios/CMB2