-
-
Save tommcfarlin/8f72a0a0507005f54fbd to your computer and use it in GitHub Desktop.
[WordPress] Remove an Enqueued Stylesheet in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'wp_enqueue_scripts', array( $this, 'remove_older_font_awesome' ), 99 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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