fbpx
Use these snippets to load ACF JSON files from more than one directory

ACF JSON is a great tool for version-controlling, deploying, and syncing ACF field groups across installations. Sometimes, however, having just the one acf-json dir can feel like a limitation.

Fortunately, ACF allows us to register multiple load points which makes it possible to move ACF JSON files wherever they make the most sense.

Register a secondary directory to load ACF JSON from

Use this snippet to load an additional directory for your ACF JSON files.

<?php
add_filter( 'acf/settings/load_json', function ( $paths ) {
$paths[] = get_template_directory() . '/some/custom/dir';
return $paths;
} );

Register multiple load points for ACF JSON

Let’s say you have multiple directories containing ACF JSON definitions that you’d like to load your fields from. You can easily do this by registering multiple load points.

<?php
add_filter( 'acf/settings/load_json', function ( $paths ) {
$paths[] = get_template_directory() . '/some/custom/dir';
$paths[] = WP_CONTENT_DIR . '/uploads/some/custom/dir';
$paths[] = '/some/system/path/dir';
return $paths;
} );

Just one caveat…

ACF won’t save field updates to the load points. If the field group’s JSON file has been manually moved to a custom load point and the field group is updated in the WordPress admin, a new JSON file will be created in ACF’s JSON save directory.

Keep up to date with all things ACF!

Subscribe to our newsletter or follow @awesomeacf on Twitter!