Home>Support>Dequeue styles from So Widgets loaded in widget areas

Dequeue styles from So Widgets loaded in widget areas

Notice: This thread is over two years old; the information may be outdated. Please consider creating a new thread if you require free support. If you have an active SiteOrigin Premium license, you can email our premium support desk at [email protected].

Hi there,

I have a custom theme which loads FontAwesome by default on every page, thus it’s not needed to load SiteOrigin fontawesome version, as it would be a duplicate.

I’ve already managed to remove the FontAwesome version loaded from /plugins/so-widgets-bundle/icons/fontawesome/style.css with the code below, thanks to help of Alex S (as far as I remember) which pointed out that styles and script are attached at the_content level.

// Dequeue SiteOrigin FontAwesome
if( class_exists( 'SiteOrigin_Widgets_Bundle' ) ) {
	function so_never_awesome($content) {
		wp_dequeue_style( 'siteorigin-widget-icon-font-fontawesome');
		return $content;
	}
	add_action( 'the_content', 'so_never_awesome', 999); 
}

However, I use the Layout Builder widget to handle Header Area & Footer Area layouts too, which is a very effective solution.

And here comes the problem: If I have an Icon widget inside any widget area, then the code above does not work (I think it’s because the_content has already been processed, and the styles loaded in widget area are attached to another hook).

I’ve tried with several common hooks (wp_print_scripts, wp_head, wp_footer with a late priority of 999 or 9999) but none of them worked. I’ve even tried to analyze your code on github, but I’ve come up with nothing.

Can you please help? I just want to know where’s the hook in the haystack :)

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 7 years, 7 months ago frafor

    No one on this one?

  2. 7 years, 7 months ago Alex S
    Hi, I Work Here

    Hi Frafor,

    Hm. Try the following PHP instead of th previously provided following PHP:

    function so_no_fonts( $fonts ){
    	return;
    }
    add_filter( 'siteorigin_widgets_icon_families', 'so_no_fonts' );
    
  3. 7 years, 7 months ago frafor

    Hi Alex! Thanks for your reply. I could try your solution just today.

    Unfortunately it strips out all the fonts, and they stop working in the wp_admin too.

    So I’ve tried with:

    	function so_no_fonts( $fonts ){		if(!is_admin())	{			return;		}		return $fonts;	}	add_filter( 'siteorigin_widgets_icon_families', 'so_no_fonts' );

    However the widgets stopped printing the innner “” inside the sow-icon-container div. So I came up with:

    	function so_no_fonts( $fonts ){		if(!is_admin())	{			$fonts['fontawesome']['style_uri'] = 'https://';			return $fonts;		}		return $fonts;	}	add_filter( 'siteorigin_widgets_icon_families', 'so_no_fonts' );

    This is a not-ideal solution and I think i won’t keep it.

    Why do I need to keep the [‘style_uri’] value?

    Further investigation allowed me to identify why this is happening: if you look into

    so-widgets-bundle/base/base.php at function siteorigin_widget_get_icon($icon_value, $icon_styles = false), line 76

    It checks for both $widget_icons_enqueued[$family] and !empty($widget_icon_families[$family][‘style_uri’]))

    Then, if ‘siteorigin-widget-icon-font-‘.$family isn’t enqueued, it enqueues it again.

    What I’ve found is that:

    • If the Icon widget is placed in a sidebar before the_content filter, then I’m able to dequeue it with the so_never_awesome($content) function above
    • If the Icon widget is placed after the_content filter, then I still couldn’t dequeue it with any provided filter…

    Is there any chance to dequeue it somehow?

  4. 7 years, 7 months ago frafor

    NB. The editor stipped out some closing tags, and I cannot edit the post above. sorry for that.

  5. 7 years, 7 months ago frafor

    Hi there,

    After further investigation, I’ve found that:

    • It’s possible to detect the equeued ‘siteorigin-widget-icon-font-fontawesome’ css using wp_style_is() hooked in wp_footer()
    • However, it seems not possible to dequeue or deregister it from there or from wp_print_footer_scripts() or _styles
    • Maybe it depends on how WordPress handles scripts, because I cannot even register / enqueue dummy test scripts from footer’s filters

    Luckily, I managed to dequeue it by directly calling wp_dequeue_script() just after the footer area is printed. This way:

    	<footer id="colophon" class="site-footer" role="contentinfo">
    		<?php if(is_active_sidebar( 'footer-area' )) {
    			dynamic_sidebar( 'footer-area' );
    			if(wp_style_is('siteorigin-widget-icon-font-fontawesome')) {
    				wp_dequeue_style( 'siteorigin-widget-icon-font-fontawesome');
    			}
    		} ?>
    	</footer><!-- #colophon -->

    Hope this will be usefull to someone in the future,

    NB: I would really appreciate if someone with editing privileges could restore the missing closing tags in the answers above, as this topic looks a real mess.

  6. 7 years, 7 months ago Alex S
    Hi, I Work Here

    Hi Frafor,

    I’m glad you were able to find a solution. I’m going to bring this up with Braam to see if we can make this process easier overall.

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More