Aleš Sýkora / November 28, 2023 / 0 comments
ACF Local JSON with Oxygen Builder
2 min read / ACF, Custom Code, Oxygen Builder, Plugins, WordPress / Share on: Twitter, LinkedIn, Facebook
Post summary: Would you like to speed up your page? If you use Advanced Custom Fields plguin, you may try the local JSON. Local JSON is a new feature added in version 5 which saves field group and field settings as .json files within your theme. The idea is similar to caching, and both dramatically speeds up…
Would you like to speed up your page? If you use Advanced Custom Fields plguin, you may try the local JSON.
Local JSON is a new feature added in version 5 which saves field group and field settings as .json files within your theme. The idea is similar to caching, and both dramatically speeds up ACF and allows for version control over your field settings!
That sounds great isn’t it? But wait, there is a need of theme and acf-json folder. But there’s no theme when using the Oxygen Builder.
Option 1 – Enable Theme (not recommended)
Of yourse you can use the theme, you just need to add some code to your Code snippets plugin like advanced scripts to disable Oxygen filter, which changes theme location to /oxygen-is-not-a-theme
// Reverse empty stylesheet URL being returned by Oxygen.
remove_filter( 'template_directory', 'ct_disable_theme_load', 1, 1 );
remove_filter( 'stylesheet_directory', 'ct_disable_theme_load', 1, 1 );
// Override the theme name change from "oxygen-is-not-a-theme" by Oxygen.
remove_filter( 'template', 'ct_oxygen_template_name' );
Create acf-json folder with empty index.php
Then you can create a blank theme (or use Oxygen No-theme for example), create acf-json folder and add empty index.php to that folder. The content of index.php should be:
<?php
// Silence is golden.
?>
Option 2 – add new ACF JSON folder (recommended)
Second option is much better – doesn’t depend on disabling or changing Oxygen filters. This option changes the location of whole acf-json folder. In my option – the folder will be located in wp-content/uploads folder. Change the append path with code which you add to the code snippets plugin (I prefer Advanced scripts).
<?php
add_filter('acf/settings/load_json', 'my_acf_json_load_point');
function my_acf_json_load_point( $paths ) {
// remove original path (optional)
unset($paths[0]);
// append path
$paths[] = get_site_url() . '/wp-content/uploads/acf-json';
// return
return $paths;
}
?>
Fuel my passion for writing with a beer🍺
Your support not only makes me drunk but also greatly motivates me to continue creating content that helps. Cheers to more discoveries and shared success. 🍻