Deque Animation CSS

Viewed 428

I am trying to deque the animation library that came with elementor from loading on a particular page. This is the URL of the script https://wpcalculators.com.ng/wp-content/plugins/elementor/assets/lib/animations/animations.min.css?ver=3.0.16

I have used this code:

//Remove animation
function remove_animation() {
    if(is_page([19] )):
 wp_dequeue_style( 'elementor-animations' );
    endif;
}
add_action( 'wp_enqueue_scripts', 'remove_animation', 100 );

but it is not working.

I used similar code to deque Gutenberg block library from loading and it worked.

//Remove Gutenberg Block Library CSS from loading on the frontend
function smartwp_remove_wp_block_library_css() {
    if(is_page([19] )):
 wp_dequeue_style( 'wp-block-library' );
 wp_dequeue_style( 'wp-block-library-theme' );
    endif;
}
add_action( 'wp_enqueue_scripts', 'smartwp_remove_wp_block_library_css' );

I confirmed the ID of the CSS from the source code which reads:

The Id seems to be 'elementor-animations'

How else can I write the code to make it work?

Note: I know it's not working when I test the URL with pagespeed insight.

1 Answers

Probably, deregister styles before dequeuing could solve the problem

function remove_animation() {
    if ( is_page( [ 19 ] ) ):
        wp_deregister_style( 'elementor-animations' );
        wp_dequeue_style( 'elementor-animations' );
    endif;
}

add_action( 'wp_enqueue_scripts', 'remove_animation', 100 );
Related