Support » Plugin: Max Mega Menu » Dequeue scripts and styles for Mega Menu on certain pages?

  • Resolved James

    (@bonkerz)


    Hi
    Great plugin! I have a question about ability to dequeue scripts and styles for Mega Menu on certain pages.

    We only use the menu on certain pages of the site, not a couple of our landing pages, and as such, want to remove the styles and scripts from loading to speed up the loading time of the page.

    function home_page_remove_scripts(){
    if ( (!is_admin()) && is_front_page() ) {
    wp_dequeue_script( 'maxmegamenu' );
    wp_dequeue_script( 'colorbox' );
    wp_dequeue_style( 'maxmegamenu' );
    wp_dequeue_style( 'megamenu-css' );
    wp_dequeue_style( 'colorbox' );
    }
    }
    add_action( 'wp_print_styles', 'home_page_remove_scripts', 999 );

    This isn’t working (you can see above I am using different variations of calling the styles).

    Can you advise as to the best way to approach this?

    Thanks in advance from all the users of your plugin focused on performance! 🙏

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author megamenu

    (@megamenu)

    Hi James,

    Glad to hear you like the plugin 🙂

    Please try this instead:

    function home_page_remove_scripts(){
    	if ( is_front_page() ) {
    		wp_dequeue_script( 'megamenu' );
    		wp_dequeue_style( 'megamenu' );
    	}
    }
    add_action( 'wp_enqueue_scripts', 'home_page_remove_scripts', 999 );

    Perfect, thanks so much, can’t believe I hadn’t tried that (or I had and didn’t notice it worked!)

    Thanks~

    Plugin Author megamenu

    (@megamenu)

    You’re welcome 🙂

    If you have a spare minute, would you mind leaving a quick review for the plugin at the bottom of this page? It would be much appreciated!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.