Best way to remove plugins CSS/JS files?
-
Hi,
I have a load of CSS/JS files, that I’m trying to merge into just one CSS/JS file. I would use an existing plugin – BUT those tend to make it on the fly (and don’t seem to take into account things like ../foo/ URLs). So, I’ve got the following:
<?php /* Plugin Name: My Load Reducer Description: Removes unneeded and unwanted stylesheets from other plugins Version: 0.1 */ //Use a class to avoid conflicts class my_load_reducer { function __construct() { //Hook into wp_enqueue_scripts with a high priority add_action( 'wp_enqueue_style', array($this, 'deregister_styles'), 99999 ); add_action( 'wp_enqueue_scripts', array($this, 'deregister_styles'), 99999 ); add_action( 'init', 'deregister_styles', 99999 ); } function deregister_styles() { // remove stuff first... wp_deregister_style( 'login-with-ajax' ); wp_deregister_style( 'contact_form_maker_frontend' ); wp_deregister_style( 'fontawesome' ); wp_deregister_style( 'genericons' ); wp_deregister_style( 'jetpack_css' ); wp_dequeue_style( 'jetpack_css' ); wp_deregister_style( 'maxgalleria-image-tiles' ); wp_deregister_style( 'maxgalleria-image-tiles-skin-standard-css' ); wp_deregister_script( 'googlemap' ); wp_deregister_script( 'rwmb-map' ); wp_deregister_script( 'gmap_form_api' ); wp_deregister_script( 'gmap_form' ); wp_enqueue_style( "common-css", '/wp-content/common.min.css' ); } } //Instantiate the class $my_load_reducer = new my_load_reducer();
What exactly is the different with :
wp_enqueue_style
wp_enqueue_scripts
and
initFor some CSS, the first one is needed – others the 2nd one is needed, and I read somewhere about the “init” function as well (which doesn’t seem to do anything for me). One that has been annoying/avoiding me, is the JetPack CSS (I have this in my own CSS file now,so want to skip it);
$version = Jetpack::is_development_version() ? filemtime( JETPACK__PLUGIN_DIR . 'css/jetpack.css' ) : JETPACK__VERSION; wp_enqueue_style( 'jetpack_css', plugins_url( 'css/jetpack.css', __FILE__ ), array(), $version ); wp_style_add_data( 'jetpack_css', 'rtl', 'replace' );
I have tried both:
wp_deregister_style( 'jetpack_css' ); wp_dequeue_style( 'jetpack_css' );
Yet neither seem to work ?? (I’ve disabled W3 TotalCache, just so I can be sure it wasn’t a caching issue)
TIA
Andy
- The topic ‘Best way to remove plugins CSS/JS files?’ is closed to new replies.