Dequeue styles from So Widgets loaded in widget areas
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.
Need fast email support? Get SiteOrigin Premium
Replies
6No one on this one?
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' );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
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:
Is there any chance to dequeue it somehow?
NB. The editor stipped out some closing tags, and I cannot edit the post above. sorry for that.
Hi there,
After further investigation, I’ve found that:
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.
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.