I'm trying to develop a Wordpress plugin that will dequeue/deregister Font Awesome stylesheets added to a theme by certain plugins that users may install, if the theme already make use of Font Awesome.
In other words: if an administrator uses a theme that has Font Awesome font-awesome.css (or font-awesome.min.css) and he uses 2 plugins that make use of Font Awesome too, the administrator will ended up with 3 font-awesome.css (or font-awesome.min.css) stylesheets loaded.
Is there a way to check if the Font Awesome stylesheet is already loaded by the theme and if so, automatically dequeue/deregister all plugins Font Awesome stylesheets, before the theme enqueue it?
The solution I have in mind is something like this (pseudo code):
add_action( 'wp_enqueue_scripts', 'no_more_fontawesome', 999 );
function no_more_fontawesome() {
if ( src_contain ('font-awesome.css') || src_contain('font-awesome.min.css') ) {
wp_dequeue_style( that has font-awesome.css or font-awesome.min.css in src);
}
A solution might be a regex check in src for the expressions font-awesome.css and font-awesome.min.css but how to achieve this?
Any help will be greatly appreciated!