WordPress.org

Forums

WP Menu Cart
[resolved] Dequeue scripts and styles (6 posts)

  1. voltronik
    Member
    Posted 1 year ago #

    Hi,

    I'm trying to minimise the amount of stylesheets and scripts being loaded by a site i'm working on. I'm already including FontAwesome in my theme and can easily include the CSS and JS that WP Menu Cart is inserting in my own, minimised LESS and JS files.

    I've tried a number of things and added the following to my theme but it doesn't work.

    wp_dequeue_style( 'wpmenucart-icons' ); // FontAwesome
    wp_dequeue_style( 'wpmenucart' ); // Styles

    Can you tell me what I need to do remove them?

    Thanks for any help in advance,
    Jack

    http://wordpress.org/plugins/wp-menu-cart/

  2. Ewout
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Jack,
    Have you tried putting that in a function? You're probably to early to dequeue (i.e. it's not enqueued yet). If you hook into wp_print_styles it'll probably work.

    function  dequeue_styles() {
        wp_dequeue_style( 'wpmenucart-icons' ); // FontAwesome
        wp_dequeue_style( 'wpmenucart' ); // Styles
    }
    add_action('wp_print_styles', 'dequeue_styles', 99999);

    Ewout

  3. voltronik
    Member
    Posted 1 year ago #

    Thanks, that's great. That works.

    I've also done that for the js script but I'm getting the error:
    ReferenceError: Can't find variable: wpmenucart_ajax in the console.

    Is there anything I can do about this?

  4. Jeremiah
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Voltronik.

    What e-commerce plugin are you using this with? Also, is this live so we can take a look?

    Jeremiah

  5. Ewout
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Jack,
    That's because the wpmenucart script is localized. If you're not using that script anymore, you'll have to localize your own script with the wpmenucart_ajax variable:

    wp_localize_script(
    	'YOURSCRIPT',
    	'wpmenucart_ajax',
    		array(
    			'ajaxurl' => admin_url( 'admin-ajax.php' ), // URL to WordPress ajax handling page
    			'nonce' => wp_create_nonce('wpmenucart')
    		)
    );

    you have to put this after the code where you do your own wp_enqueue_script (and replace YOURSCRIPT with your own script handle).

  6. voltronik
    Member
    Posted 1 year ago #

    That worked perfectly!
    Thank you very much for your help.

    Jack

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP Menu Cart
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic