How to deregister or remove a CSS file in Wordpress? wp_dequeue_style not working

I have an old version of Font Awesome added to my WordPress website from a plugin. I want to remove that CSS and add my own latest Font Awesome CSS. I’m using the code below, but it’s not working. How can I achieve this?

add_action( 'wp_enqueue_scripts', function(){
    wp_dequeue_style('font-awesome');
    wp_deregister_style('font-awesome');   
});

I’ve been scouring the WordPress Codex and forums, but nothing seems to work.

If wp_dequeue_style and wp_deregister_style are not working as expected, it might be due to the priority of the actions.

Here’s an updated version of your code:

add_action( 'wp_enqueue_scripts', function(){
    wp_dequeue_style('font-awesome');
    wp_deregister_style('font-awesome');   
}, 9999);

By setting the priority to a higher value, like 9999, you ensure that your code runs after the plugin’s code, effectively removing and deregistering the Font Awesome CSS added by the plugin. Adjust the priority value as needed based on your specific requirements.