acf/json/save_file_name

Last updated Apr 4, 2024

Description

Used to change the filename of files saved by the ACF local JSON feature.

Changelog

  • Added in version 6.2.

Parameters

apply_filters( 'acf/json/save_file_name', $filename, $post, $load_path );
  • $filename (string) The current filename being filtered.
  • $post (array) An array of settings for the field group, post type, taxonomy, or options page being saved.
  • $load_path (string) The path on the server that the JSON file was loaded from.

Example

This example demonstrates how to change the filename of all JSON files to the ACF title.

functions.php

<?php

function custom_acf_json_filename( $filename, $post, $load_path ) {
    $filename = str_replace(
        array(
            ' ',
            '_',
        ),
        array(
            '-',
            '-'
        ),
        $post['title']
    );

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

    return $filename;
}
add_filter( 'acf/json/save_file_name', 'custom_acf_json_filename', 10, 3 );