Skip to content

Instantly share code, notes, and snippets.

@gyrus
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gyrus/e79273a8e3854f20975e to your computer and use it in GitHub Desktop.
Save gyrus/e79273a8e3854f20975e to your computer and use it in GitHub Desktop.
Wrapper for wp_head() which manages SSL
/**
* Wrapper for wp_head() which manages SSL
*
* @uses wp_head()
* @param bool $ssl
* @return void
*/
function pilau_wp_head( $ssl = false ) {
if ( ! $ssl || WP_LOCAL_DEV ) {
// Just output
wp_head();
} else {
// Capture wp_head output with buffering
ob_start();
wp_head();
$wp_head = ob_get_contents();
ob_end_clean();
// Replace plain protocols
$wp_head = preg_replace( '/(["\'])http:\/\//', '\1https://', $wp_head );
// Replace specific URLs
$wp_head = str_replace( '//w.sharethis.com', '//ws.sharethis.com', $wp_head );
// Output
echo $wp_head;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment