how remove font to increase site speed load

in my site(zamiin.ir) there are some font that slow my site speed . font fa-solid-900.woff2 two time load in my site ,one time in my theme and one time in elementor

gtmetrix test: what can i do?

Topic plugins themes Wordpress

Category Web


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.