How to get Advanced Custom Fields to load JSON files from more than one directory

If you use Advanced Custom Fields a lot you are probably using ACF’s very awesome Local JSON feature.

By default, ACF saves and loads all JSON files from the acf-json directory inside your theme but it is possible to take control of ACF’s behaviour to define your own custom load points as outlined in the Advanced Custom Fields documentation.

By adding your own directories, you are able to define many points within your app that can’t be easily overridden by people working with the custom fields in the WordPress admin. Being able to load from many directories also makes it possible for you to bundle your field groups into component-based directories which you could use to build and maintain a library of portable UI components…ooh-la-la!

How to register your own ACF JSON load points

As you can see from the above snippet, it’s super easy to define your own ACF JSON load directories.

Auto registering all subdirectories as ACF JSON load points

Let’s say you have a components directory which contains multiple directories, each representing a component, and each of these components contain their own ACF JSON files. An easy way to handle loading JSON files from each would be to simply read the directory with PHP and register each subdirectory:

One last thing…

If you liked this article, I'd be incredibly grateful if you tweeted about it.

Also, I don't send emails often but when I do, I try to fill them full of useful goodies. If you like code snippets & dev tips, join my mailing list. There's no catch but I'll probably want to tell you about any new plugins & tools I build.