plugins – how remove font to increase site speed load

Question

You can either make a child theme, or make a plugin. Within that child theme or plugin, you’ll dequeue one of the copies. If you don’t have any other theme customizations, it probably makes the most sense to create a custom plugin.

Both your theme and your plugin are paid, so you’ll need to look through their code to find out how they enqueue the font. Specifically, you are looking for a call to wp_enqueue_style that includes the URL, something similar to this:

wp_enqueue_style( 'load-fa', 'https://use.fontawesome.com/releases/v5.5.0/css/all.css' );

or

function wp_styles() {
    wp_register_style( 'font-awesome', plugins_url( 'wp-plug-in/css/font-awesome.min.css' ) );
    wp_enqueue_style( 'font-awesome' );
}

What you’re trying to find is the “handle,” which in the first example is “load-fa” and in the second example is “font-awesome”. Once you identify the handle, your plugin can be as simple as:

<?php
/** Plugin Name: Remove duplicate FA
*/

add_action( 'wp_enqueue_scripts', 'dedupe_font_awesome', 100 );

function dedupe_font_awesome() {
     // Change the text within quotes to the handle you found.
     wp_dequeue_style( 'handle-goes-here' );
}

You’ll definitely need to change the ‘handle-goes-here’ part, and it’s possible you might have to adjust the number 100. That is a priority, telling WP to execute your code after any code that’s registered with a lower number. If no number is present in the enqueue call, it is the default 10, meaning your 100 will fire after it, find Font Awesome, and remove it.

0
zamiin group 4 months 2022-05-04T17:04:31-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse