Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save joelstransky/053d18846d3e42631aec773e4346e2ca to your computer and use it in GitHub Desktop.
Save joelstransky/053d18846d3e42631aec773e4346e2ca to your computer and use it in GitHub Desktop.
Advanced Custom Fields acf-json support for child themes
<?php
/**
* Child theme support for acf-json
* This will load acf-json from the parent theme first.
* That way if a child theme's acf-json folder contains a .json
* file with the same name as the parent, it will get loaded second
*/
add_filter('acf/settings/save_json', function() {
return get_stylesheet_directory() . '/acf-json';
});
add_filter('acf/settings/load_json', function($paths) {
// $paths will already include the result of get_stylesheet_directory ie. parent theme's acf-json
if(is_child_theme()) {
$paths[] = get_template_directory() . '/acf-json';
}
return $paths;
});
@nickberens360
Copy link

@joeltransky Greetings, do you put this in the child functions.php or the parents?

@aaronsummers
Copy link

aaronsummers commented Jun 25, 2020

@joeltransky Greetings, do you put this in the child functions.php or the parents?

This goes into your parent theme. Very useful.

@artneo-io
Copy link

Wow, is this in the ACF documentation? I've been searching for a solution for a long time, trying to understand why a simple child theme (with just the style.css file) was crashing my WordPress site with the PHP fatal error: "Allowed memory size of X bytes exhausted". Thank you so much for the code snippet! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment