Several years ago, not really having a handle on the best practice for running a MultiSite network, I often network activated plugins. Later I realized this was a mistake because not all the sites used some of the plugins. So I have unnecessary scripts and stylesheets on several sites.
What I've started doing for those unwanted plugin resources is wp_dequeue_style( 'style-sheet' );
and wp_deregister_style( 'style-sheet' );
in child-theme functions.php
My problem is that it doesn't work for all plugins. For example, https://wordpress.org/plugins/advanced-recent-posts/ is not following my function. I thought perhaps I would try to remove_action();
but I am not familiar with how this exactly works.
Here's what I'm working with in my functions.php and it works for other style-sheets.
function remove_unwanted_stylesheets() {
wp_dequeue_style( 'wp-advanced-rp-css' );
wp_deregister_style( 'wp-advanced-rp-css' );
}
add_action( 'wp_enqueue_scripts', 'remove_unwanted_stylesheets', 999 );
The plugin enqueue and add action is as follows.
function add_advanced_recent_posts_widget_stylesheet() {
$plugin_dir = 'advanced-recent-posts-widget';
if ( @file_exists( STYLESHEETPATH . '/advanced-recent-posts-widget.css' ) )
$mycss_file = get_stylesheet_directory_uri() . '/advanced-recent-posts-widget.css';
elseif ( @file_exists( TEMPLATEPATH . '/advanced-recent-posts-widget.css' ) )
$mycss_file = get_template_directory_uri() . '/advanced-recent-posts-widget.css';
else
$mycss_file = plugins_url( 'css/advanced-recent-posts-widget.css',dirname(__FILE__) );
wp_register_style( 'wp-advanced-rp-css', $mycss_file );
wp_enqueue_style( 'wp-advanced-rp-css' );
}
add_action('wp_print_styles', 'add_advanced_recent_posts_widget_stylesheet');
Any insight into how I can effectively dequeue and unregister the stylesheet for this plugin is greatly appreciated.