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 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,
Holger -
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
-
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).
-
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
Post is closed for comments.
Comments
10 comments