Enqueue/Include neutral urls for http and/or https in WordPress

Taken from here: http://wordpress.stackexchange.com/a/81897/13712

URLs must have a https or http protocol for WordPress to enqueue them.

FIf possible you should use get_template_directory_uri() (for parent themes) or get_stylesheet_directory_uri() (for child themes) as both of these handle SSL if necedssary. Here’s an example:

// CUSTOM pp_ JAVASCRIPTS
 wp_register_script( 'pp_js', THEME_INCLUDES.'/pp_js_min.js', array( 'jquery' ), $theme['Version'], true);
 wp_enqueue_script("pp_js");

If you can’t enqueue your own local script/s and have to enqueue from an outside source or not even enqueue at all, you can detect which protocol is in use and then use that. See here:

$http_protocol = is_ssl() ? 'https' : 'http';
define( 'HTTP_PROTOCOL', $http_protocol );

Then use ‘HTTP_PROTOCOL’ like this:

// Google Maps API
wp_enqueue_script('google-maps', HTTP_PROTOCOL.'://maps.google.com/maps/api/js?sensor=false');

or

echo '<script src="'.HTTP_PROTOCOL.'://html5shim.googlecode.com/svn/trunk/html5.js"></script>'; // Google's HTML5 Shim

Revisions

Tags: ,

No comments yet.

Leave a Reply