wordpress / latest / functions / wp_replace_insecure_home_url.html

wp_replace_insecure_home_url( string $content ): string

Replaces insecure HTTP URLs to the site in the given content, if configured to do so.

Description

This function replaces all occurrences of the HTTP version of the site’s URL with its HTTPS counterpart, if determined via wp_should_replace_insecure_home_url() .

Parameters

$content string Required
Content to replace URLs in.

Return

string Filtered content.

Source

File: wp-includes/https-migration.php. View all references

function wp_replace_insecure_home_url( $content ) {
	if ( ! wp_should_replace_insecure_home_url() ) {
		return $content;
	}

	$https_url = home_url( '', 'https' );
	$http_url  = str_replace( 'https://', 'http://', $https_url );

	// Also replace potentially escaped URL.
	$escaped_https_url = str_replace( '/', '\/', $https_url );
	$escaped_http_url  = str_replace( '/', '\/', $http_url );

	return str_replace(
		array(
			$http_url,
			$escaped_http_url,
		),
		array(
			$https_url,
			$escaped_https_url,
		),
		$content
	);
}

Uses

Uses Description

Changelog

Version Description
5.7.0 Introduced.

© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_replace_insecure_home_url