3

Wordpress is loading all client resources of all plugins, not just the plugin of interest. It may make sense to load jqery globally but it makes no sense to load all other plugin's Javascript in a back-end plugin.

Now, how can I prevent that Wordpress is loading other plugin's resources?

There's wp_dequeue but I am not sure there is another callback at the end of loading all plugins, so I can clean it up alltogether myself. I am currently interested in filtering back-end plugin resources only.

ps: i am really stuck at this and I am actually very surprised that it seems to be designed like this, I mean, wp_enque is fine but WP doesn't care for what it is ,so you need to do all the leg-work yourself. Simply imagine 2+ different Dojo/CommonJS/Require-JS based applications with their own configs and versions being loaded : trouble non stop, that's what I am facing now.

thank you, any idea is welcome.

  • This is a real problem and there are no real, meaningful solutions aside from convincing plugin & theme developers that they need to conditionally load their css/js – Will Jul 1 '14 at 12:24
  • yeah, I figured that out now too. i think WP needs to tune its API and design as well in regard of back-end interfaces. – stackoverclan Jul 1 '14 at 14:54
  • It tends to be badly written plugins that are the issue. The enqueue system works pretty well if it's used properly. – Andy Macaulay-Brook Aug 8 '16 at 9:50
1

You could try echoing wp_head and wp_footer to see what they contain but unfortunately that'll miss stuff some of the authors hardcode. Basically what I do is wp_dequeue/wp_deregister based on what I see being loaded in either the source, error-logs or even just looking within each of the installed plugins to see whats being called. I find it easier to download production sites to my local dev environment. Using Notepad++ I then click Search -> Find in all files -> Specify the plugins dir (or themes) on my local development environment and search for patterns like wp_enqueue even *.js and so on since I get a better picture and what can be loaded. I then make the needed changes on the live environment.

If you identify scripts you do not want, Pop them into a function that looks something like this inside your themes function.php file:

function wp_getridofscript() {
   wp_dequeue_script( 'jquery-ui-core' );
   wp_deregister_script( 'jquery-ui-core' );
}
add_action( 'wp_print_scripts', 'wp_getridofscript', 100 );

You can have as many as you want and don't need to bother writing a separate function for each. IE:

function wp_getridofscript() {
   wp_dequeue_script( 'jquery' );
   wp_deregister_script( 'jquery' );
   wp_dequeue_script( 'jquery-ui-core' );
   wp_deregister_script( 'jquery-ui-core' );
}
add_action( 'wp_print_scripts', 'wp_getridofscript', 100 );
| improve this answer | |
  • Just wanted to add that for styles you would use wp_dequeue_style('handle'); and wp_deregister_style( 'handle' ); respectively. See: wp_dequeue_script and wp_dequeue_style – Jason Brennecke Sep 11 '16 at 4:12
  • Whoops Nevermind my answer.... I overlooked the part of the question where you mentioned wp_dequeue and misread. – Jason Brennecke Sep 11 '16 at 4:50
0

This is always a problem when using a plugin that loads extra css/js files. You could add custom fields to the pages where you want to exclude css and js files (called something like page_exclude_css and _js), with comma separated style and script handlers as it's values. Then you add a function to to the wp_enqueue hooks (at a position like 9999) that dequeues all those handlers.

| improve this answer | |
  • looks good, will need to check it out, thanks for now! – stackoverclan Mar 30 '15 at 20:40
0

As there is no handle names assigned by a central repository, it is just impossible for plugins to avoid creating their own handle names, and even if there were a central repository, some plugins will need to use version 3 of a JS library while others need version 4 (actually happened to me with select2 library), therefor a simple naming scheme might not be enough even if one existed.

The end result of this situation is that any attempted solution will be an ad-hoc, and will not be "future prof". If you are owning a site, at least you can see what plugins are enqueuing and dequeue them, if you write a theme or plugin there is just nothing more to do than try to test against popular themes and plugins and adjust your code based on the amount of smooth integration you want with them.

| improve this answer | |

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.