WordPress Plugin // Remove video player
Hi,
even it´s a nice tool, but I want to remove the unpkg.com Video player script - as there is no video on the page and therefore no player would be needed. The corresponding script blocks the loading of the page and is mentioned in the Google Lighthouse test under "remove unused Javascript".
I´ve tried to deque / deregister the script via a function in the funcions.php file - but unfortunately it doesn´t work. Here´s the script being used in the functions.php:
//Dequeue Video Player
function remove_cld_player() {
wp_dequeue_script( 'cld-player-js' );
wp_deregister_script( 'cld-player-js' );
}
add_action( 'wp_print_scripts', 'remove_cld_player' );
"cld-player-js" is the id of the script. The script is still loaded in the footer of the page.
Looking forward to any kind of help on this topic.
Many thanks in advance!
-
Hi Holger,
We are aware of this issue where scripts are being loaded even when not used and are working on mitigating the issue.
In the meantime, let me check with my team if there is a custom hook we could share in order to not run the script.
Hope that makes sense.
Best,
Loic
0 -
Hi Loic,
once again I need to say, that I REALLY appreciate your support! Many thanks for your reply and help!
I´ve tried different solutions regarding the loading time of the function, or using "wp_print_scripts ()", "
wp_dequeue_script
()" or "wp_enque_script() - but nothing helped.
So if you maybe could help me with a custom hook - that would be awesome!
If there would be anything I could provide to help - just let me know ...
Many thanks in advance
Best,
Holger0 -
Hi Holger,
May I ask you to try this custom hook:
<?php
function remove_cld_player() {
if ( ! is_admin() ) {
wp_dequeue_script( 'cld-core' );
wp_dequeue_script( 'cld-player' );
}
}
add_action( 'wp_print_scripts', 'remove_cld_player', 100 );
function remove_cld_player_styles() {
if ( ! is_admin() ) {
wp_dequeue_style( 'cld-player' );
wp_dequeue_style( 'cld-player-local' );
}
}
add_action( 'wp_print_styles', 'remove_cld_player_styles', 100 );Thanks for letting me know if that works for you.
Best,
Loic
0 -
Hi Loic,
BIG thanks for your kind help and the custom hook! But it seems, the script(s) are a little bit "persistent" ;). I´ve tried your code, but both of the scripts are still being loaded. So I did some other tries also with
if
( ! is_user_logged_in() )
and furthermore changing the script names to "cld-player-js" or "cld-core-js". Finally it ended up with this code:
function remove_cld_player()
{
if ( ! is_admin() ) {
wp_dequeue_script('cld-core', 'https://unpkg.com/cloudinary-core@2.6.3/cloudinary-core-shrinkwrap.min.js', array(), '2.6.3', true);
wp_dequeue_script('cld-player', 'https://unpkg.com/cloudinary-video-player@1.4.0/dist/cld-video-player.min.js', array(), '1.4.0', true);
}
}
add_action('wp_print_scripts', 'remove_cld_player', 100 );
function remove_cld_player_style() {
if ( ! is_admin() ) {
wp_dequeue_style( 'cld-core' );
wp_dequeue_style( 'cld-player' );
}
}
add_action('wp_print_scripts', 'remove_cld_player_style', 100 );but anyhow - despite all the attempts, the scripts are still loaded (Browser Cache has been cleared each time).
0 -
Hi Holger,
Thanks for getting back to me.
I am checking internally this script. Also, for your information, this issue will be fixed in our next release on Monday, so it may not be worth spending time on this and wait for the version 2.7.0.
Hope that makes sense.
Best,
Loic
0 -
Hi Loic,
big thanks for your update, especially regarding the upcoming release on Monday!
Therefore - you can close this topic. There would be no more need for a "deeper investigation" or manual coding. The topic is not so urgent, that I can not wait until the next update :)I want to say a big thanks for your outstanding and kind support, which I´ll recommend to my circle of friends and acquaintances, as well as Cloudinary itself.
Best,
Holger
0 -
Hi Holger,
Thanks for the update and the kind words.
I'll reach out to you through the thread when we have released the new version.
In the meantime, I wish you a great weekend.
Best,
Loic
0 -
Hi Holger,
Hope you are doing well.
We have just released the version `2.7.0` of our plugin, could you please upgrade and see if that fixes your issue.
Thanks in advance.
Best,
Loic0 -
Hi Loic,
many thanks for your info! I´ve just intalled the new version - and: the player script wasn´t loaded anymore! ;) Perfect! Thank you for including this topic in your update!
Best,
Holger0 -
Hi Holger,
Thanks for confirming it is working, I am glad we were able to help.
Have a great rest of the day.
Best,
Loic
0
Post is closed for comments.
Comments
10 comments