Self-hosted FontAwesome in a child theme

Font files are stored within the theme’s directory and are referenced via the get_stylesheet_directory_uri() function. The stylesheets are incorporated into the theme using WordPress’s wp_enqueue_style() function, ensuring they do not conflict with other plugins or themes. Lastly, this function is hooked into the wp_enqueue_scripts action, making sure the icons are available throughout your site without affecting loading times or performance.

function load_font_awesome() {
    // Get the URI of the stylesheet
    $font_awesome_uri = get_stylesheet_directory_uri() . '/fontawesome/css/fontawesome.min.css';
    $font_awesome_solid = get_stylesheet_directory_uri() . '/fontawesome/css/solid.css';
    $font_awesome_brands = get_stylesheet_directory_uri() . '/fontawesome/css/brands.css';

    
    wp_enqueue_style('font-awesome', $font_awesome_uri);
    wp_enqueue_style('font-awesome-solid', $font_awesome_solid);
    wp_enqueue_style('font-awesome-brands', $font_awesome_brands);
}


add_action('wp_enqueue_scripts', 'load_font_awesome');

WordPress Hooks