• Resolved endlessloving

    (@sebastians)


    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://ww.wp.xz.cn/plugins/wp-miniaudioplayer/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter endlessloving

    (@sebastians)

    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

    Thread Starter endlessloving

    (@sebastians)

    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.