WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I use wp_enqueue_script so that I get protocol neutral URLs? Here is how I'm currently using it:

<?php wp_enqueue_script('name', get_bloginfo('template_directory'). '/js/name.pack.js'); ?>

I saw that home_url() is protocol aware so I figured theme_url() would be also but I'm getting the error below when I use it.

Call to undefined function theme_url()

share|improve this question
up vote 6 down vote accepted

You can't -- URLs must have a protocol for WordPress to enqueue them. What you can do, though, is detect which protocol to use and then use that.

$protocol = is_ssl() ? 'https' : 'http';
$url = "$protocol://example.com/resource";

But for enqueuing scripts from your theme, you should use get_template_directory_uri() or get_stylesheet_directory_uri() which already handle SSL:

wp_enqueue_script('name', get_stylesheet_directory_uri() . '/js/name.pack.js');
share|improve this answer

You can also leave off the protocol, like this:

wp_enqueue_style( 'be-fonts', '//fonts.googleapis.com/css?family=Ubuntu:300,400,500' );
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.