Skip to content

Instantly share code, notes, and snippets.

@iCaspar
Last active September 21, 2017 19:50
Show Gist options
  • Save iCaspar/e34e93c5c3d761fcc6e80c24a5ca6c2e to your computer and use it in GitHub Desktop.
Save iCaspar/e34e93c5c3d761fcc6e80c24a5ca6c2e to your computer and use it in GitHub Desktop.
<?php
add_action( 'widgets_init', 'ic_remove_simple_social_css', 999 );
function ic_remove_simple_social_css() {
global $wp_registered_widgets;
$widgetNames = array_keys( $wp_registered_widgets );
$ssWidgets = [];
foreach ( $widgetNames as $name ) {
if ( false !== strpos( $name, 'simple-social-icons' ) ) {
$ssWidgets[] = $name;
}
}
foreach ( $ssWidgets as $widget ) {
$widgetObject = $wp_registered_widgets[ $widget ]['callback'][0];
remove_action( 'wp_head', [ $widgetObject, 'css' ] );
}
}
@iCaspar
Copy link
Author

iCaspar commented May 8, 2017

Removing the CSS from the simple social icons widget requires finding the widget object. This sorts through all the widgets that are registered in the WP global $wp_registered_widgets to see if the widget has been registered, and if it has, grabs the object from the registered widgets array and unregisters the action. Your mileage may vary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment