WordPress.org

Ready to get started?Download WordPress

Forums

Events Manager
[resolved] Disable unnecessary javascript on frontend (12 posts)

  1. AdamBarry
    Member
    Posted 1 year ago #

    I am using this plugin to list gigs for my band's website. The only features that I want to display on the front end are: the list of events, the individual events pages, google maps on those pages and the sidebar widget.

    I understand that if I disable the javascript and CSS I will break the backend functionality which I would like to retain.

    So how would I go about disabling the javascript and CSS on the frontend that I do not need without affecting the backend functionality?

    Thanks

    Adam

    http://wordpress.org/extend/plugins/events-manager/

    EDIT: Looking at the events manager CSS file, I would need to copy the Google Maps styling over to my own CSS files.

  2. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    Hi, you could try this to your themes functions.php file :

    function my_em_disable_scripts(){
    	remove_action('init', array('EM_Scripts_and_Styles','public_enqueue'));
    	remove_action('init', array('EM_Scripts_and_Styles','localize_script'));
    }
    if ( !is_admin() ) add_action('init','my_em_disable_scripts',100);
  3. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    note that this may change in a few updates because of a recently added hook, we'd change 'init' to 'wp_enqueue_scripts'

  4. AdamBarry
    Member
    Posted 1 year ago #

    Thanks for the reply.

    I've just tried your suggested solution and nothing happens. Do you have any other suggestions? I looked at this previous topic but I don't know how to implement it and it seems like it would break the backend functionality.

  5. agelonwl
    Member
    Posted 1 year ago #

    you can try that link and just paste those snippet to your theme functions.php or use @Marcus suggestion http://wordpress.org/extend/plugins/use-google-libraries/

  6. AdamBarry
    Member
    Posted 1 year ago #

    OK, so I've ended up using the Google libraries because my aim anyway was to reduce any unnecessary page load. Is there anyway of disabling the Events Manager CSS from loading? I just want to include the bits needed for Google Maps in my own stylesheets.

    Thanks for the help

  7. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    that didn't work for me either... try this one

    /**
     * Disables all scripts and styles from EM and Pro front-end
     */
    function my_em_disable_scripts_styles(){
    	remove_action('init', array('EM_Scripts_and_Styles','public_enqueue'));
    	if( !is_admin() ){
    		global $EM_Pro;
    		remove_action('init', array($EM_Pro,'enqueue_script'), 1);
    		remove_action('wp_head', array($EM_Pro,'wp_head'));
    		remove_action('wp_head',array('EM_Coupons', 'wp_head'));
    	}
    }
    add_action('plugins_loaded','my_em_disable_scripts_styles', 100);

    Use Google Libraries is quite good in this respect, WP by default loads UI files one by one whereas UGL loads the minified ui library in one go.

  8. AdamBarry
    Member
    Posted 1 year ago #

    Hello again. Using the google libraries plugin resolved the page load concern that I had, however it broke another plugin I was using called backstretch. I'm trying a few solutions to get both to work. Would it be possible to change the code below in events-manager.php to enqueue the single jquery.ui.min.js file from google?

    function public_enqueue() {
    		//Scripts
    		wp_enqueue_script('events-manager', plugins_url('includes/js/events-manager.js',__FILE__), array('jquery', 'jquery-ui-core','jquery-ui-widget','jquery-ui-position','jquery-ui-sortable','jquery-ui-datepicker','jquery-ui-autocomplete','jquery-ui-dialog')); //jQuery will load as dependency
    		//Styles
    		wp_enqueue_style('events-manager', plugins_url('includes/css/events_manager.css',__FILE__)); //main css
    	}

    Obviously for updates I could keep the edited snippet and paste it back into the file when needed.

  9. AdamBarry
    Member
    Posted 1 year ago #

    I have solved my issue, although it is not desirable I have edited a plugin file (I can live with it, I'll just do the same when updates come out!). All the features that I need work with just jquery enabled so I stopped the UI elements from loading by deleting them from the array. I didn't need the CSS either so I took the google maps styles and put them in my own stylesheet then stopped the wp_enqueue style.

  10. Daedalon
    Member
    Posted 1 year ago #

    If a plugin encounters problems with Use Google Libraries, it might be fixable by reporting it to the plugin author as in this case: http://wordpress.org/support/topic/plugin-query-wrangler-interface-not-working

    Everything that Events Manager enqueue's can be removed from the queue. For any script queued with http://codex.wordpress.org/Function_Reference/wp_enqueue_script, the opposite function is http://codex.wordpress.org/Function_Reference/wp_enqueue_script, and for http://codex.wordpress.org/Function_Reference/wp_register_script there is http://codex.wordpress.org/Function_Reference/wp_deregister_script.

    Then there are also http://codex.wordpress.org/Function_Reference/remove_action that Marcus's example uses and the rest depending what exactly is intended to be removed.

  11. Mohammad Sabbagh
    Member
    Posted 1 year ago #

    Hi Marcus,

    any updates about this

    how we can control the en-queued scripts

    for example if i am using only the events calender i dont think i need 13 Javascript files

    i try to dequeue some files but i noticed that dequeue any one will remove all of them

    and then its not possible to enqueue the needed files

    Thanks for the plugin and effort

  12. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    We have an easy way to do this now via the Events > Settings > Performance Optimization.

    I suggest using the plugin Use Google Libraries, those multiple jQuery UI files become 1 minified CDN file.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic