[Hustle Pro] Plugin adding style sheet links to bottom of page.

Is there a way to disable Hustle ( or any plugin for that matter) from adding the style sheet link to the bottom of my page? I notice that the sheets are not enqueued so I cant dequeue them. I would like to control all the style references in my child theme style sheet so there are fewer requests.

  • Panos
    • SLS

    Hi Lee!

    For Hustle you can use the hustle_disable_front_styles as Nithin mentioned. For example the following will disable style for all modules:
    add_filter( 'hustle_disable_front_styles', '__return_true' );

    If you need to disable that only for specific module ids (specific popup/embed/slide in/social sharing id) you can use the filter like this :

    add_filter( 'hustle_disable_front_styles', function( $disable, $module, $renderer ){
    
    	$disable_for_module_ids = array( 5, 6, 8 );
    
    	if ( in_array( $module->module_id, $disable_for_module_ids ) ) {
    		$disable = true;
    	}
    
    	return $disable;
    }, 20, 3 );

    Similarly if you need to disable for specific module types (only for popups or only for slide ins or a combination ) you can use the following:

    add_filter( 'hustle_disable_front_styles', function( $disable, $module, $renderer ){
    
    	$disable_for_module_types = array(
    		'popup',
    		'embedded',
    		'slidein',
    		'social_sharing'
    	);
    
    	if ( in_array( $module->module_type, $disable_for_module_types ) ) {
    		$disable = true;
    	}
    
    	return $disable;
    }, 20, 3 );

    You can add these snippets in your child theme’s functions.php file since you are alrady using one, or you can even add them in a mu-plugin. In case you are not familiar with mu-plugins you can read about them here:
    https://wpmudev.com/docs/getting-started/download-wpmu-dev-plugins-themes/#create-the-mu-plugin-file

    or any plugin for that matter

    It depends. Every plugin might use different approaches so those need to be checked separately.

    Hope this helps :slight_smile:

  • Lee
    • Freelance WP Developer

    Excellent. Thanks gentlemen! I will give it a whirl and let you know how I get on.

    For my reference, is there a consolidated list of all available filters for WPMUDEV plugins? This would be very helpful to know for any potential future customization’s.

    Thanks again.

  • Lee
    • Freelance WP Developer

    So I tried this out and the styles were definitely affected, essentially giving the pop-up vanilla styling. However, when I view the page source, there are still HTTP requests to the style sheets (4 in total that look like this <link rel=’stylesheet’ id=’hustle_popup-css’ …….</link>, etc). What I am interested in is moving all required styles to my child theme and removing the http request to the separate native style sheets.

  • Panos
    • SLS

    I think with the following :

    add_filter( 'style_loader_tag', function( $html, $handle, $href, $media ){
    
    	$exclude_tags_for = array(
    		'hustle_popup',
    		'hustle_social',
    		'hustle_inline',
    		'hustle_float',
    		'hustle_slidein',
    		'hustle_icons',
    		'hustle_global',
    		'hustle_info',
    		'sui_styles',
    		'hstl-source-code-pro',
    		'hstl-roboto',
    		'hstl-opensans'
    	);
    
    	if ( in_array( $handle, $exclude_tags_for ) ) {
    		return;
    	}
    	
    	return $html;
    
    }, 20, 4 );

    the rest will be removed too.

    However I’m not sure if this is the best way to go. Hustle enqueues only the scripts/styles that are required for the modules to load per page. By removing them all you will then need to do the condition checks manually so you load only the scripts you need. If the required styles are not loaded you could end up either not seeing anything or with some broken css that affects functionality. Since Hustle is designed to work in that way I’m not sure we can keep up supporting if something goes wrong when not used as it’s meant to be.

    Something else I’d like to mention, since I am not sure how you will be inserting these style tags, in case you are using asset optimization plugins (eg Hummingbird’s Asset Optimization), if those are not enqueued correctly you won’t be able to manage the optimization part properly.

    I mentioned the above so I’m sure you are aware of these scenarios :slight_smile:

    Kind regards!

  • Lee
    • Freelance WP Developer

    Thats great info. Thank you Panos. I’m most interested in just understanding how it all works so I have options and awareness…(.call me a control freak :wink: and it helps with my development growth. I really appreciate your time.

  • tohaitrieu
    • New Recruit

    My problem is the same.

    And I use this code snippet to fix this:

    
    function totrieu_remove_hustle() {
    if (!is_single()){
    wp_dequeue_style( 'hustle_icons' );
    wp_deregister_style( 'hustle_icons' );
    wp_dequeue_style( 'hustle_global' );
    wp_dequeue_style( 'hustle_optin' );
    wp_dequeue_style( 'hustle_inline' );
    wp_deregister_style( 'hustle_inline' );
    }
    }
    add_action('wp_footer', 'totrieu_remove_hustle', 10);
    

    I only use the email form at the single post. And I want to remove all script, style from other page.

    Because Hustle register all stylesheet at the wp_footer. I think we have to use the add_action(‘wp_footer’, your_function’, 10); to remove stylesheet.

    Thank you.

  • tohaitrieu
    • New Recruit

    And Remove Hustle JS from some specific pages:

    //Remove JS
    function totrieu_remove_js_from_home() {
    if (is_front_page() || is_home() || is_category() || is_tag()){
    wp_dequeue_script( ‘hui_scripts’ );
    wp_dequeue_script( ‘hustle_front’ );
    wp_dequeue_script( ‘optin_admin_fitie’ );
    }
    }
    add_action( ‘wp_print_scripts’, ‘totrieu_remove_js_from_home’, 100);