Last active
August 29, 2015 14:19
-
-
Save gyrus/e79273a8e3854f20975e to your computer and use it in GitHub Desktop.
Wrapper for wp_head() which manages SSL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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