Skip to content

Instantly share code, notes, and snippets.

@qutek
Created October 6, 2014 09:25
Show Gist options
  • Save qutek/7e0642a35e84bb5ca8fd to your computer and use it in GitHub Desktop.
Save qutek/7e0642a35e84bb5ca8fd to your computer and use it in GitHub Desktop.
[Wordpress] Replace https
function filter_content_match_protocols( $content ) {
$search = $replace = get_bloginfo( 'home' );
if ( ! preg_match( '|/$|', $search ) )
$search = $replace = "$search/";
if ( is_ssl() ) {
$search = str_replace( 'https://', 'http://', $search );
$replace = str_replace( 'http://', 'https://', $replace );
}
else {
$search = str_replace( 'http://', 'https://', $search );
$replace = str_replace( 'https://', 'http://', $replace );
}
$content = str_replace( $search, $replace, $content );
return $content;
}
ob_start( 'filter_content_match_protocols' );
function filter_content_match_protocols_end() {
ob_end_flush();
}
add_action( 'shutdown', 'filter_content_match_protocols_end', -10 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment