wp_replace_insecure_home_url() WordPress Function

The wp_replace_insecure_home_url() function is used to replace any insecure home URL with the secure home URL. This is useful for ensuring that any links on your website are using the secure HTTPS protocol.

wp_replace_insecure_home_url( string $content ) #

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().


Top ↑

Parameters

$content

(string)(Required)Content to replace URLs in.


Top ↑

Return

(string) Filtered content.


Top ↑

Source

File: wp-includes/https-migration.php

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
	);
}


Top ↑

Changelog

Changelog
VersionDescription
5.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.