ACF lets you build metaboxes, Gutenberg blocks, and more with their easy-to-use interface. These custom fields are stored in the database and then rendered in the WordPress backend for you – no code required.
This can become an issue if you’re using a modern development workflow: building locally, testing on a development/staging environment, then deploying to production. Since you likely aren’t overwriting the production database with the development one, any metaboxes created in development will need to be re-created in production.
ACF has a built-in feature to help called Local JSON. If you create a folder in your theme named
acf-json/, ACF will automatically add/update a JSON file for every group of fields. These JSON files can then be version controlled with the rest of your theme.
After pushing the code changes to production, log into the production site, go to Custom Fields in the backend, and click “Sync available” to manually sync the updated metaboxes.
I prefer having the metabox changes automatically update on production rather than having to manually sync them.
I also prefer using a core functionality plugin for any site-specific functionality that isn’t directly theme related. If the website owner would expect something to keep working after changing themes, it belongs in a functionality plugin.
In my core functionality plugin, I have a
acf.php file with the following features:
- Store the JSON files in the core functionality plugin, in a
- Automatically sync new metaboxes. For performance reasons we limit the sync to new versions of the core functionality plugin, when the
CORE_FUNCTIONALITY_VERSIONconstant has changed.
- Only display the ACF field editor if
WP_LOCAL_DEV === true. I have this constant defined in wp-config.php locally. This prevents clients from accidentally editing or deleting their metaboxes.
- Register an options page. I’ve commented it out, but most sites we build leverage an options page so I can quickly turn it on.
- Register new blocks. It’s also commented out but easily accessible so I don’t have to keep referring to my article on building Gutenberg blocks with ACF.