• Resolved snippet24

    (@snippet24)


    So basically I noticed this plugin loads the Material Design styles and scripts in every page which is bad for performance, please improve this.

    • This topic was modified 4 years, 1 month ago by snippet24.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author GusRuss89

    (@gusruss89)

    Hi @snippet24,

    Unfortunately there’s no way the plugin to know in advance which page includes a contact form, which is why the scripts load on every page. However, if you as the site owner know which pages the script is required on, you can quite easily take care of this manually.

    You can add this to your functions.php. It will dequeue all the plugin scripts and styles except on pages with slug ‘contact’ or ‘form’. You will need to change the if condition to suit your pages.

    function my_dequeue_cf7md_assets() {
        if( ! is_page( 'contact' ) && ! is_page( 'form' ) ) {
            wp_dequeue_script( 'md-components-js' );
            wp_dequeue_script( 'autosize' );
            wp_dequeue_script( 'cf7-material-design' );
            wp_dequeue_style( 'cf7md_roboto' );
            wp_dequeue_style( 'cf7-material-design' );
        }
    }
    add_action( 'wp_enqueue_scripts', 'my_dequeue_cf7md_assets', 20 );

    There are some old threads that go into a bit more detail if you need further help. Here’s the most recent: https://www.ads-software.com/support/topic/prevent-scripts-from-loading-on-all-pages/

    Thanks,
    Angus

    Thread Starter snippet24

    (@snippet24)

    Hi, thank you so much Angus!! I have no problem setting it that way so that should do just fine ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Only load libraries on the pages that contain MD forms’ is closed to new replies.