Protocol Relative Enqueues

With the http/2 and https features of WordPress on the future plan, it’s time for a reminder about how to enqueue things. If you haven’t read John’s post about https configurations, please do. We want to make things work well for everyone and future proof your code 🙂

A common method to enqueue fonts is to use the CSS url like this:

wp_enqueue_style( 'my_awesome_css', 'http://somecoolurl.com/my-awesome.min.css' );

The problem with this, as we move to more and more of an https world, is that will cause errors with people who want that beautiful green padlock. In order to make their life easier, please use protocol relative URLs in your enqueues:

wp_enqueue_style( 'my_awesome_css', '//somecoolurl.com/my-awesome.min.css' );

It’s really that simple. The future will thank you.

Edit: Yes, if a url has HTTPS and you can use it, use it. Eventually we’ll all be https and none of this will matter, but hard coding in http is making life difficult 🙂

#schema