WordPress.org

Ready to get started?Download WordPress

Forums

MailChimp List Subscribe Form
Unnecessary loading of main_css makes site slow! (11 posts)

  1. akostrubiak
    Member
    Posted 1 year ago #

    I have the Mailchimp plugin set up on my site to not use custom styling, however the styles are still queued up to be loaded when my pages load. For whatever reason, the loading of these styles is very slow (>1sec, in some cases nearly 5 sec) and in turn, slows my entire site down.

    It seems that these styles are loaded up at the bottom of mailchimpSF_load_resources(), but are not conditionally loaded. I have not had the opportunity to play with it yet, but I don't understand why these styles would always be loaded if we're given the option of not using custom styling. I think that the loading of these styles should be guarded by something along the lines of if (get_option('mc_custom_style') == 'on' && !is_admin()).

    Is the non-conditional loading of these styles done by design? Or is it a bug?

    http://wordpress.org/extend/plugins/mailchimp/

  2. wpmnger
    Member
    Posted 1 year ago #

    You can create a function in your functions.php and add these lines to remove the css

    wp_dequeue_style('mailchimpSF_main_css');
    	wp_dequeue_style('mailchimpSF_ie_css');
  3. akostrubiak
    Member
    Posted 1 year ago #

    You can create a function in your functions.php and add these lines to remove the css [snip]

    Awesome, thanks - that did the trick.

    Still curious though if always loading those styles is the "correct" behavior. Either way, this fix solves my issues :)

  4. alextaylor
    Member
    Posted 1 year ago #

    I have exactly the same problem - trying to optimise our site has flagged up the mailchimp plugin as being a real laggard.
    @wpmnger- when you say 'create a function' what exactly do you mean? Do I just need to copy and paste those 2 lines into my functions.php file, or add something else around them? Do I paste them in anywhere in the file, top, bottom?
    Thanks for your help

  5. akostrubiak
    Member
    Posted 1 year ago #

    Maybe there's a more proper way to do it, but inserting the following into your functions.php file seemed to do the trick for me.

    add_action('init', 'my_mcsf_fix', 10);
    function my_mcsf_fix() {
    	wp_dequeue_style('mailchimpSF_main_css');
    	wp_dequeue_style('mailchimpSF_ie_css');
    }
  6. alextaylor
    Member
    Posted 1 year ago #

    Hi Akostrubiak
    That code gave me a fatal error I'm afraid.
    I then tried removing the first line of that code, and although it got rid of the error, it didn't get rid of the mailchimp styles either :(
    What am I doing wrong? Are there anything other options?

  7. wpmnger
    Member
    Posted 1 year ago #

    It's a question of sequence. You could use wp_enqueue_scripts.

    example

    function your_prefix_remove_styles() {
    	wp_dequeue_style('mailchimpSF_main_css'); //remove unnecessary Mailchimp styles
    	wp_dequeue_style('mailchimpSF_ie_css'); //remove unnecessary Mailchimp styles
    
    }
    add_action( 'wp_enqueue_scripts', 'your_prefix_remove_styles', 11 );
  8. akostrubiak
    Member
    Posted 1 year ago #

    @wpmnger, would adding my function to the end of wp_enqueue_scripts be the "appropriate" place for that code? It's been a while since I've had my head deep inside wordpress.

    Thanks!

  9. wpmnger
    Member
    Posted 1 year ago #

    Sorry, I didn't clarify: using the action 'init' should be saved for other things and not for scripts and styles. For that you should use the action 'wp_enqueue_scripts'.

    That way you are not removing a script or style that has not yet been registered or enqueued.

  10. alextaylor
    Member
    Posted 1 year ago #

    Hi wpmnger

    Thanks for the follow up. Copying and pasting that code into my functions.php file at the start still throws a fatal error - Fatal error: Call to undefined function add_action()
    Is there a specific place it needs to be in the functions file? I couldn't find anything else called enqueue in that file.

    Also, I noticed that MC has a 'naked' version of their sign up form, just html, which might be worth trying out as their plugin doesn't do much with all the js and css overhead that it loads and the dodgy styling of the form. Has anyone tried this, any downsides?

  11. wpmnger
    Member
    Posted 1 year ago #

    @akostrubiak I can't speak as to 'appropriate' but I think it's the right place for anything related to scripts. Here is what the codex says:

    wp_enqueue_scripts is the proper hook to use when enqueuing items that are meant to appear on the front end. Despite the name, it is used for enqueuing both scripts and styles.

    I think it is safe to say that this applies for dequeuing and deregistering as well.

    @alextaylor You can place this code anywhere in your theme's functions.php file. The error you are getting could be from multiple reasons and most likely not relating to this code snippet. Try a clean WP install with no plugins other than MailChimp.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic