I have encountered a problem with enqueuing and dequeuing style CSS sheets with font Awesome. In my functions.php child theme file I try to dequeue a default one and download a new version from CDN server.
It worked 100% fine until I introduced "Move render-blocking JavaScript." part of the code. With code below no CSS stylesheet from CDN is loaded and instead of maybe 50 ms of time to get woff file, according to GTmetrix and pingdom it now takes around 600ms while getting from my FTP's Storefront theme fonts folder (btw I have no idea why the difference is so huge).
I even tried better font awesome plugin for Wordpress instead of my font snippet, but outcome is just the same - works without moving scripts, doesn't work with it.
// Move render-blocking JavaScript.
function custom_clean_head() {
remove_action('wp_head', 'wp_print_scripts');
remove_action('wp_head', 'wp_print_head_scripts', 9);
remove_action('wp_head', 'wp_enqueue_scripts', 1);
add_action('wp_footer', 'wp_print_scripts', 5);
add_action('wp_footer', 'wp_print_head_scripts', 5);
add_action('wp_footer', 'wp_enqueue_scripts', 5);
}
add_action( 'wp_enqueue_scripts', 'custom_clean_head' );
// Specify FontAwesome character set early.
add_action( 'wp_enqueue_scripts', 'layers_child_styles', 100);
add_action( 'wp_footer', 'load_awesome', 1);
if( ! function_exists( 'layers_child_styles' ) ) {
function layers_child_styles(){
wp_dequeue_style('layers-font-awesome');
wp_dequeue_style('font-awesome');
}
function load_awesome() {
wp_enqueue_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css', $deps = array(), $ver = false);
}
}
Try This
// Remove and Unregister Styles
function layers_child_styles(){
wp_dequeue_style('layers-font-awesome');
wp_dequeue_style('font-awesome');
wp_deregister_style('font-awesome');
}
add_action( 'wp_print_styles', 'layers_child_styles', 999);
// Add Additional Script or style
function load_awesome() {
wp_enqueue_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css');
}
add_action( 'wp_enqueue_scripts', 'load_awesome' 999);