Use Human-Readable ACF JSON Filenames

Replace default ACF JSON filenames like group_64a1b2c3.json with readable names for cleaner version control diffs.

php json
|

Replace default ACF JSON filenames like group_64a1b2c3.json with readable names for cleaner version control diffs.

Use the acf/json/save_file_name filter to generate filenames from the field group title:

<?php
add_filter( 'acf/json/save_file_name', function ( $filename, $post, $load_path ) {
    $filename = str_replace(
        [
            ' ',
            '_',
        ],
        [
            '-',
            '-',
        ],
        $post['title']
    );

    $filename = strtolower( $filename ) . '.json';

    return $filename;
}, 10, 3 );

Before — hard to identify in git:

acf-json/
├── group_64a1b2c3d4e5f.json
├── group_78f9a0b1c2d3e.json
└── group_90d1e2f3a4b5c.json

After — meaningful filenames:

acf-json/
├── event-details.json
├── hero-section.json
└── team-member.json

Save field groups, post types, and taxonomies to separate directories (ACF 6.2+):

<?php
add_filter( 'acf/settings/save_json/type=acf-field-group', function () {
    return get_stylesheet_directory() . '/acf-json/field-groups';
} );

add_filter( 'acf/settings/save_json/type=acf-post-type', function () {
    return get_stylesheet_directory() . '/acf-json/post-types';
} );

add_filter( 'acf/settings/save_json/type=acf-taxonomy', function () {
    return get_stylesheet_directory() . '/acf-json/taxonomies';
} );

// Tell ACF to also load from these directories.
add_filter( 'acf/json/load_paths', function ( $paths ) {
    $paths[] = get_stylesheet_directory() . '/acf-json/field-groups';
    $paths[] = get_stylesheet_directory() . '/acf-json/post-types';
    $paths[] = get_stylesheet_directory() . '/acf-json/taxonomies';
    return $paths;
} );

Stay Updated

Get ACF tips and new extensions in your inbox

No spam. Unsubscribe anytime.