Title: only load styles and scripts when needed
Last modified: August 22, 2016

---

# only load styles and scripts when needed

 *  Resolved [jlooooo](https://wordpress.org/support/users/jlooooo/)
 * (@jlooooo)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/only-load-styles-and-scripts-when-needed/)
 * Hi,
 * I am trying to load styles and scripts only where needed: login, register and
   single posts. However, I am running into difficulties due to the way the plugin
   handles JS files.
 * This is working:
 * `wp_dequeue_style('the-champ-frontend-css');`
 * But this is not, when load js in footer is checked in admin:
 * `wp_dequeue_script('the_champ_ss_general_scripts');`
 * I could use this:
 * `remove_action('init', 'the_champ_init', 1);`
 * But conditionals are not available yet on init.
 * Could you tell me how I can achieve conditional loading of JS files of the Super
   Socializer plugin?
 * I would recommend using [http://codex.wordpress.org/Function_Reference/wp_register_script](http://codex.wordpress.org/Function_Reference/wp_register_script).
   There is an argument to load javascript in footer. This way wp_dequeue_script
   would still work.
 * Thanks!
 * [https://wordpress.org/plugins/super-socializer/](https://wordpress.org/plugins/super-socializer/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Rajat Varlani](https://wordpress.org/support/users/the_champ/)
 * (@the_champ)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/only-load-styles-and-scripts-when-needed/#post-5713285)
 * Hi,
 * You can use the following code to deregister scripts after unchecking the `load
   js in website footer` option
    `wp_dequeue_script('the_champ_ss_general_scripts');`
   And then include the required scripts manually in footer.
 * > I would recommend using [http://codex.wordpress.org/Function_Reference/wp_register_script](http://codex.wordpress.org/Function_Reference/wp_register_script).
   > There is an argument to load javascript in footer. This way wp_dequeue_script
   > would still work.
 * Thanks, I will include it in the plugin in upcoming releases.
 *  Thread Starter [jlooooo](https://wordpress.org/support/users/jlooooo/)
 * (@jlooooo)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/only-load-styles-and-scripts-when-needed/#post-5713453)
 * Hi,
 * I unchecked load js in footer and used
    ` wp_dequeue_script(‘the_champ_ss_general_scripts’);‘
   with some conditional logic, so I didn’t have to include the scripts again.
 * Further, I would like to request to make some effort to conditionally load js
   and css files where needed. I can see you already do this to some end, but there
   is definitely room for improvement :-). The plugin is loading a lot of scripts
   and that’s such a shame if not needed, performance wise.
 * Thanks for the support.
 *  Plugin Author [Rajat Varlani](https://wordpress.org/support/users/the_champ/)
 * (@the_champ)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/only-load-styles-and-scripts-when-needed/#post-5713456)
 * Okay, I will improve this too in upcoming releases. Thanks
 *  Thread Starter [jlooooo](https://wordpress.org/support/users/jlooooo/)
 * (@jlooooo)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/only-load-styles-and-scripts-when-needed/#post-5713459)
 * Great!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘only load styles and scripts when needed’ is closed to new replies.

 * ![](https://ps.w.org/super-socializer/assets/icon-128x128.png?rev=1866723)
 * [Social Share, Social Login and Social Comments Plugin - Super Socializer](https://wordpress.org/plugins/super-socializer/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/super-socializer/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/super-socializer/)
 * [Active Topics](https://wordpress.org/support/plugin/super-socializer/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/super-socializer/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/super-socializer/reviews/)

## Tags

 * [.js files](https://wordpress.org/support/topic-tag/js-files/)
 * [conditional](https://wordpress.org/support/topic-tag/conditional/)

 * 4 replies
 * 2 participants
 * Last reply from: [jlooooo](https://wordpress.org/support/users/jlooooo/)
 * Last activity: [11 years, 4 months ago](https://wordpress.org/support/topic/only-load-styles-and-scripts-when-needed/#post-5713459)
 * Status: resolved