0

I have an own class that deregisters all scripts and styles and creates 2 cached files one for scripts and one for styles that is registered in the end. This runs inside theme, my problem is that I cant move it into plugin, as soon as i move it into plugin it wont work.

currently this code works inside theme

add_filter('wp_print_styles', array($this, 'optimize_styles'), 1);
add_filter('wp_print_scripts', array($this, 'optimize_scripts'), 1);

i have tried add action add filter, change priorities.... also i want some way to make my plugin load as last to ensure all plugin styles and scripts will be "compiled" into one.

Thankyou

  • Without seeing your code I am not sure how to address your problem. – s_ha_dum Jun 11 '15 at 15:03
  • To load your custom plugin last, remember that plugins do load by alphabetical order of plugin's folder name (not by plugin's name). So name it ZZ... :) – WisdmLabs Jun 18 '15 at 14:01
  • @ErikKubica There's a much better/"correct" way to do this - see my answer. – TheDeadMedic Jun 25 '15 at 9:55
1

There's a much better and more reliable way than naming your plugin "ZZ" - use a delayed hook on plugins_loaded, which fires after all plugins are loaded:

function wpse_191178_plugins_loaded() {
    // Do your stuff
}

add_action( 'plugins_loaded', 'wpse_191178_plugins_loaded', 100 );
0

Since plugins are loaded by the alphabetical order of plugin's folder name (not by plugin's name), name your plugin folder ZZ.. and it should load last :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.