Thread Starter
caraya
(@caraya)
The SO thread is not applicable. wp_dequeue_script only works with script files and this is not the case here.
The Cloudinary script is inlined on the page’s head and there is no ID that I can use with the script to footer plugin to keep it in the head.
Hi @caraya,
We are looking into this plugin as it does some drastic things like removing WP Core actions instead of filtering out the scripts.
I’ll get back to you asap.
Loic
Thread Starter
caraya
(@caraya)
Interesting observation. The plugin doesn’t remove anything you don’t tell it to, but I would love to hear more about it.
I’ll wait for your feedback.
Hi there,
This 3rd party plugin does remove all the actions from the wp_head.
You could check their class-stf-public.php file.
Regards,
Wissam
Thread Starter
caraya
(@caraya)
For most scripts that are files, either part of WP core or part of a plugin, STF provides a way to keep it in the head.
Since Cloudinary writes the script on the head and doesn’t provide an ID or any other way to identify the script for STF to keep in the head, I thought I would ask here. This is why I asked if you provided a way to keep the generated script on the head.
This is a performance optimization and not being able to keep Cloudinary in the head of the page and Cloudinary breaking if you move it to the footer prevents me from using it
Hi @caraya,
You should be able to use this code either in your functions.php or as part of a mu-plugin
<?php
/**
* Ensure that the lazy load assets are loaded in the head.
*/
add_action(
'cloudinary_ready',
static function() {
// Is Cloudinary lazy load bypassed.
$bypass = apply_filters(
'cloudinary_bypass_lazy_load',
false,
array(
'atts' => array(
'class' => '',
),
)
);
// Check if the default core actions were removed, and Cloudinary lazy load is not bypassed.
if ( ! $bypass && ! has_action( 'wp_head', 'wp_print_scripts' ) ) {
$plugin = Cloudinary\get_plugin_instance();
$lazy_load = $plugin->get_component( 'lazy_load' );
// Add back Cloudinary lazy load assets to the head.
add_action( 'wp_head', array( $lazy_load, 'enqueue_assets' ) );
}
}
);
Please let me know how it goes.
Loic
Thread Starter
caraya
(@caraya)
Loic,
It fixed the problem. The scripts have been moved to the footer and the images loaded from Cloudinary still work.
Thanks!
Hi @caraya,
Glad it works!
Feel free to reach out here or via [email protected] if you need anything else.
Best,
Loic