wordpress enqueue fontawesome issues

I’m trying to enqueue font awesome only if haven’t been enqueued before.

This is my code:

function stylesheet_installed($array_css)
{
    global $wp_styles;

    foreach( $wp_styles->queue as $style ) 
    {
        foreach ($array_css as $css)
        {
            if (false !== strpos( $wp_styles->registered[$style]->src, $css ))
                return 1;
        }
    }
    return 0; 
}

This function seems to be ok.

function add_scripts(){
    $font_awesome = array('font-awesome', 'fontawesome');
    if (stylesheet_installed($font_awesome) === 0)
    {
         // ALWAYS ENQUEUE FONT-AWESOME, NO MATTER THE CONDITION ABOVE
         wp_enqueue_style('font-awesome', '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css'); 
    }    
}  
add_action( 'wp_enqueue_scripts', 'add_scripts' );

However, something is wrong because font-awesome always is enqueued even when the helper function returns 1 (do not enqueue again).

I’m stuck with this, any help will be appreciated, thank you!

Read more here: wordpress enqueue fontawesome issues

Leave a Reply

Your email address will not be published. Required fields are marked *