Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created November 17, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tommcfarlin/8f72a0a0507005f54fbd to your computer and use it in GitHub Desktop.
Save tommcfarlin/8f72a0a0507005f54fbd to your computer and use it in GitHub Desktop.
[WordPress] Remove an Enqueued Stylesheet in WordPress
<?php
add_action( 'wp_enqueue_scripts', array( $this, 'remove_older_font_awesome' ), 99 );
<?php
/**
* Determines whether or not Font Awesome is already loaded. This is necessary because other plugins,
* theme styles, or add-ons may include Font Awesome and we don't want to include it if it's already
* been included.
*/
public function remove_older_font_awesome() {
global $wp_styles;
// Read all of the existing styles.
$sources = array_map( 'basename', (array) wp_list_pluck( $wp_styles->registered, 'src' ) );
// Look for any pre-existing Font Awesome styles.
$result = array_search( 'font-awesome.min.css', $sources );
if ( ! $result ) {
$result = array_search( 'font-awesome.css', $sources );
}
// Deregister the pre-existing file.
if ( $result ) {
wp_deregister_style( $result );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment