Hello,
Thanks for the feedback!
Each layouts stylesheets files should be unique, because those files are enqueued using a unique handle generated using the layout name. As you can see on your screenshot, each handles are unique, this is why it is included multiple times even if the file is the same.
In your case, if you have a unique CSS file and want to include it only once, you should not use the “CSS Style” file path in the layouts settings, and enqueue your file using the acfe/flexible/enqueue hook. See documentation. Usage example:
add_action('acfe/flexible/enqueue/name=my_flexible', 'my_acf_flexible_enqueue', 10, 3);
function my_acf_flexible_enqueue($field, $layout, $is_preview){
wp_enqueue_style('my-style', get_stylesheet_directory_uri() . '/assets/my-style.css');
}
Hope it helps!
Have a nice day!
Regards.
Thread Starter
rose18
(@rose18)
Thank!
I did try using that method, but I am getting a fatal error on the page editor.
Please find it below.
Fatal error: Uncaught ArgumentCountError: Too few arguments to function sp_acfe_flexible_enqueue(), 2 passed in /XXXX/site/wp-includes/class-wp-hook.php on line 303 and exactly 3 expected in /XXXX/site/wp-content/mu-plugins/modified_vendor_hooks.php:105 Stack trace: #0 /XXXX/site/wp-includes/class-wp-hook.php(303): sp_acfe_flexible_enqueue(Array, true) #1 //XXXX/site/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters('', Array) #2 /XXXX/site/wp-includes/plugin.php(470): WP_Hook->do_action(Array) #3 /XXXX/site/wp-content/plugins/acf-extended/includes/fields/field-flexible-content-preview.php(227): do_action('acfe/flexible/e...', Array, true) #4 /XXXX/site/wp-includes/class-wp-hook.php(303): acfe_field_flexible_content_preview->render_field(A in /XXXX/site/wp-content/mu-plugins/modified_vendor_hooks.php on line 105
This is the code that I am using:
function sp_acfe_flexible_enqueue($field, $layout, $is_preview){
wp_enqueue_style('sp-acfe-block-style', get_stylesheet_directory_uri() . '/assets/admin-acfe-blocks.css');
}
Thanks!
Hello,
The error “Too few arguments to function …, 2 passed in…” means there is a problem in hooks arguments number.
Sorry there is a mistake in the documentation. When using that hook to target the whole Flexible Content, there are only 2 arguments:
add_action('acfe/flexible/enqueue/name=my_flexible', 'my_acf_flexible_enqueue', 10, 2);
function my_acf_flexible_enqueue($field, $is_preview){
wp_enqueue_style('my-style', get_stylesheet_directory_uri() . '/assets/my-style.css');
}
See the 10, 2 in the hook, and the $field, $is_preview arguments in the function.
You have access to the third $layout argument only when targeting a specific layout in a Flexible Content. Example:
add_action('acfe/flexible/enqueue/layout=my_layout', 'my_acf_layout_enqueue', 10, 3);
function my_acf_layout_enqueue($field, $layout, $is_preview){
wp_enqueue_style('my-style', get_stylesheet_directory_uri() . '/assets/my-style.css');
}
In your case you should use the first example. I just updated the documentation to fix it, thanks for the report!
Regards.