Title: Load plugin files and code conditionally
Last modified: August 30, 2016

---

# Load plugin files and code conditionally

 *  Resolved [endlessloving](https://wordpress.org/support/users/sebastians/)
 * (@sebastians)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/load-plugin-files-and-code-conditionally/)
 * Hi there,
 * this is a great plugin. I am so happy that things like this are available for
   free. 🙂 Thank you Pupunzi!
 * I am wondering if there is any way to load the js and the css code conditionally,
   meaning only when there is actually an mp3 link in the page or maybe in dependency
   of a custom field value?
 * I have only one page with mp3 files on my site but the player files are loaded
   on every page which makes the loading of pages slower without any benefit. It
   would be great if there is an option for it in the plugin settings or another
   way to actually check if the plugin files are actually needed on a page/post.
 * Or maybe as a work-around, it there a way to unregister the scripts in the functions.
   php?
 * [https://wordpress.org/plugins/wp-miniaudioplayer/](https://wordpress.org/plugins/wp-miniaudioplayer/)

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

 *  Thread Starter [endlessloving](https://wordpress.org/support/users/sebastians/)
 * (@sebastians)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/load-plugin-files-and-code-conditionally/#post-6612175)
 * Unfortunately it is nor possible to the scripts from this plugin without touching
   the plugin files.
 * The reason is clear when you read this here:
 * > The dirty truth
   > Not all plugins use the appropriate methods for loading scripts and styles.
   > Some developers just drop stuff right in the header. This is usually because
   > they’re not familar with two important WordPress functions: wp_enqueue_script()
   > and wp_enqueue_style(). If your plugin/theme author isn’t using these functions,
   > please encourage them to do so. It allows the rest of us to work with their
   > code using the methods WordPress provides.
 * Hey,
    it would be awesome if you could do that! 🙂
 * Have a read here to get a better understanding of the topic:
    [http://inspirationalpixels.com/tutorials/remove-plugin-scripts-wordpress](http://inspirationalpixels.com/tutorials/remove-plugin-scripts-wordpress)
 *  Thread Starter [endlessloving](https://wordpress.org/support/users/sebastians/)
 * (@sebastians)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/load-plugin-files-and-code-conditionally/#post-6612183)
 * I found the solution. I looked into the plugin file and found the actions that
   I need to remove conditionally so that the css and js is not loaded on pages 
   where I don’t need it.
 * This code here works:
 *     ```
       add_action('template_redirect', function() {
   
       		if(!is_page(817)) : // this could even be a custom field value or something else to check for
       			remove_action('init', 'miniAudioPlayer_init');
       			remove_action('wp_head', 'maplayer_custom_css');
       			remove_action('wp_footer', 'miniAudioPlayer_player_head',20);
       		endif;
   
       });
       ```
   

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

The topic ‘Load plugin files and code conditionally’ is closed to new replies.

 * ![](https://ps.w.org/wp-miniaudioplayer/assets/icon.svg?rev=983692)
 * [mb.miniAudioPlayer - an HTML5 audio player for your mp3 files](https://wordpress.org/plugins/wp-miniaudioplayer/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-miniaudioplayer/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-miniaudioplayer/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-miniaudioplayer/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-miniaudioplayer/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-miniaudioplayer/reviews/)

 * 2 replies
 * 1 participant
 * Last reply from: [endlessloving](https://wordpress.org/support/users/sebastians/)
 * Last activity: [10 years, 8 months ago](https://wordpress.org/support/topic/load-plugin-files-and-code-conditionally/#post-6612183)
 * Status: resolved