Created
November 13, 2019 06:49
-
-
Save justinhough/aba00fccfa4f878d0d940d1ebc6de441 to your computer and use it in GitHub Desktop.
WP Advanced Custom Fields - Save and Load via JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* ACF Custom Fields - Save and Load | |
* | |
* When ACF fields are added or updated this will save the output to JSON | |
* where they can be version controlled and loaded on Production sites. | |
* For best usage the production database should not contain any ACF | |
* in the database. | |
* | |
* @package | |
*/ | |
function my_acf_json_save_point( $path ) { | |
// update path | |
$path = get_stylesheet_directory() . '/custom-fields'; | |
// return | |
return $path; | |
} | |
add_filter('acf/settings/save_json', 'my_acf_json_save_point'); | |
function my_acf_json_load_point( $paths ) { | |
// remove original path (optional) | |
unset($paths[0]); | |
// append path | |
$paths[] = get_stylesheet_directory() . '/custom-fields'; | |
// return | |
return $paths; | |
} | |
add_filter('acf/settings/load_json', 'my_acf_json_load_point'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Create a separate file include file that gets added to
functions.php
like so,require get_template_directory() . '/inc/acf.php';