Skip to content

Instantly share code, notes, and snippets.

@lgladdy
Last active January 11, 2024 16:09
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lgladdy/48863dfc593da85130e4140ce8fd35bc to your computer and use it in GitHub Desktop.
Save lgladdy/48863dfc593da85130e4140ce8fd35bc to your computer and use it in GitHub Desktop.
ACF 6.2 custom load and save paths for ACF JSON
<?php
add_filter( 'acf/json/load_paths', 'set_custom_json_load_paths' );
function set_custom_json_load_paths( $paths ) {
$paths[] = get_stylesheet_directory() . '/acf-json/post-types';
$paths[] = get_stylesheet_directory() . '/acf-json/field-groups';
$paths[] = get_stylesheet_directory() . '/acf-json/taxonomies';
$paths[] = get_stylesheet_directory() . '/acf-json/option-pages';
return $paths;
}
add_filter( 'acf/settings/save_json/type=acf-post-type', 'set_custom_json_save_path_for_post_types' );
function set_custom_json_save_path_for_post_types() {
return get_stylesheet_directory() . '/acf-json/post-types';
}
add_filter( 'acf/settings/save_json/type=acf-field-group', 'set_custom_json_save_path_for_field_groups' );
function set_custom_json_save_path_for_field_groups() {
return get_stylesheet_directory() . '/acf-json/field-groups';
}
add_filter( 'acf/settings/save_json/type=acf-taxonomy', 'set_custom_json_save_path_for_taxonomies' );
function set_custom_json_save_path_for_taxonomies() {
return get_stylesheet_directory() . '/acf-json/taxonomies';
}
add_filter( 'acf/settings/save_json/type=acf-ui-options-page', 'set_custom_json_save_path_for_option_pages' );
function set_custom_json_save_path_for_option_pages() {
return get_stylesheet_directory() . '/acf-json/option-pages';
}
add_filter(
'acf/json/save_file_name',
function( $filename, $post, $load_path ) {
return empty( $load_path ) ? $filename : basename( $load_path );
},
10,
3
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment