Disable styles in front
-
Hello,
How to disable/remove styles/css in front of the_flexible() function?
I want to load them with vitejs compilation, not from WordPress basic queuing and the_flexible() function.
Do you know how to solve my problem?
Thanks in advance.
-
Hello,
Thanks for the feedback!
The Flexible Content Dynamic Render scripts/styles are enqueued right after the
the_flexible()usage on the front-end.If you don’t want to enqueue those files, but rather do it manually outside of the WordPress logic, there are two solutions:
- Leave the script/style settings empty in your layouts, and enqueue your files using your own method.
- If you want to keep these layout settings, but don’t ant to enqueue them, then you’ll have to overwrite the handles to avoid them being enqueued.
You can achieve that by registering styles/scripts with empty paths inside the
wp_enqueue_scriptsWP hook (See documentation).ACF Extended generate handles with the Flexible Content field name and the Layout name, using this pattern
{flexible_content_name}-layout-{layout_name}.So for a Flexible Content names “my_flexible”, handles will be called:
- my_flexible-layout-my_hero
- my_flexible-layout-my_gallery
- etc…
Here is a usage example to overwrite these handles with an empty path:
add_action('wp_enqueue_scripts', 'my_enqueue_scripts'); function my_enqueue_scripts(){ // prevent acfe automatic style enqueue wp_register_style('my_flexible-layout-my_hero', false); wp_register_style('my_flexible-layout-my_gallery', false); }Hope it helps!
Have a nice day!
Regards.
Hello,
Thanks!
Its work with “-” not “_” like:
add_action('wp_enqueue_scripts', 'my_enqueue_scripts'); function my_enqueue_scripts() { // prevent acfe automatic style enqueue wp_register_style('titre-sous-le-header-layout-titre-fond-couleur', false); wp_register_style('titre-sous-le-header-layout-titre-fond-couleur', false); }Have a great day!
Oops, sorry you are right.
Handles are generated using
acf_slugify()which effectively convert underscore into hyphen, as you pointed out.The correct examples are:
- my-flexible-layout-my-hero
- my-flexible-layout-my-gallery
- etc…
Have a nice day!
Regards.
Thanks, i forgot to show my final solution to eliminate all css load by the_flexible() function:
function layout_get($content): void { foreach ($contenus as $layout) { foreach ($layout['layouts'] as $value) { $handle = acf_slugify($layout['name']) . '-layout-' . acf_slugify($value['name']); // prevent acf automatic style enqueue wp_register_style($handle, false); wp_register_style($handle, false); wp_register_script($handle, false); wp_register_script($handle, false); }}} // Remove styles in front only add_action('wp_enqueue_scripts', function () { layout_get(acf_get_fields('group_xxxx')); });-
This reply was modified 3 years, 4 months ago by
Antoine Greuzard.
-
This reply was modified 3 years, 4 months ago by
Antoine Greuzard.
-
This reply was modified 3 years, 4 months ago by
Antoine Greuzard.
Hello,
Thanks for sharing! This is a cleaver way to deal with all layouts enqueue automatically!
I’ve noted on my to-do list to add a way to bypass layouts enqueue more easily, to make things even more clean. Maybe using a setting or filter.
I also noted this ticket URL, so I’ll let you know once I find a proper solution.
I don’t have any ETA yet tho, I need to think about the implementation first.
Have a nice day!
Regards.
The topic ‘Disable styles in front’ is closed to new replies.