You are viewing an old revision of this post, from August 6, 2014 @ 11:39:54. See below for differences between this version and the current revision.

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: [php]// CUSTOM pp_ JAVASCRIPTS wp_register_script( 'pp_js', THEME_INCLUDES.'/pp_js_min.js', array( 'jquery' ), $theme['Version'], true); wp_enqueue_script("pp_js");[/php] 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: [php]$http_protocol = is_ssl() ? 'https' : 'http'; define( 'HTTP_PROTOCOL', $http_protocol );[/php] Then use 'HTTP_PROTOCOL' like this: [php]// Google Maps API wp_enqueue_script('google-maps', HTTP_PROTOCOL.'://maps.google.com/maps/api/js?sensor=false');[/php] or [php]echo '<script src="'.HTTP_PROTOCOL.'://html5shim.googlecode.com/svn/trunk/html5.js"></script>'; // Google's HTML5 Shim[/php]

Revisions

  • August 6, 2014 @ 11:39:54 [Current Revision] by PeterLugg
  • August 6, 2014 @ 11:39:54 by PeterLugg

Revision Differences

There are no differences between the August 6, 2014 @ 11:39:54 revision and the current revision. (Maybe only post meta information was changed.)

Tags: ,

No comments yet.

Leave a Reply