Is it safe to enqueue a font style without putting http or https?

I have seen a few WordPress sites and tutorials enqueuing fonts like this. Does this work with http and https sites? Is it safe to do this? I see these exact URL’s in the source code when testing this function on an http site.

add_action('wp_enqueue_scripts', 'theme_external_styles');
function theme_external_styles(){
    wp_enqueue_style( 'main_css', '//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css' );
    wp_enqueue_style( 'roboto', '//fonts.googleapis.com/css?family=Roboto:400,300,100,500,700,500italic,400italic,300italic,100italic,700italic' );
}

1 Answer
1

Yes this is fine and is a good practice, especially if your site may switch between HTTPS/HTTP (like for a shopping cart etc) that way you are not loading mixed content.

As long as the CDN you are pulling from offers both HTTPS and HTTP you’re fine, which they do.

Leave a Comment