SOLVED: update_option: siteurl and home in multisite subsites to https://

I want rewrite the siteurl and home options on multisite subsites.

In wp-admin/option.php this is it:

if ( !is_multisite() ) {
if ( !defined( ‘WP_SITEURL’ ) )
$whitelist_options[‘general’][] = ‘siteurl’;
if ( !defined( ‘WP_HOME’ ) )
$whitelist_options[‘general’][] = ‘home’;

Now I try updating this options in my theme’s functions.php file:

`add_action( ‘after_setup_theme’, ‘update_forceurl’ );
function update_forceurl() {
$xsiteurl = get_site_url();
$find = array( ‘http://’ );
$replace = ‘https://’;
$finalurl = str_replace( $find, $replace, $xsiteurl );

update_option( ‘siteurl’, $finalurl );
update_option( ‘home’, $finalurl );


Add these code to the functions.php file of your subsite’s theme, immediately after the initial ”


$xsiteurl = get_option( ‘home’ );
$find = array( ‘http://’, ‘https://’ );
$replace = ”;
$pureaddress = str_replace( $find, $replace, $xsiteurl );
$ssladdress = ‘https://’ . $pureaddress . ”;
if ( $xsiteurl != $ssladdress ) {
update_option( ‘siteurl’, ” . $ssladdress . ” );
update_option( ‘home’, ” . $ssladdress . ” );

Originally the best it would have been the get_option( ‘siteurl’ ), that determine the “$xsiteurl”, but this code deprecated, and the wordpress recommend that use it instead the site_url(), because “equivalent functionality”, BUT THIS FALSE:
If you use the get_site_url() on a multisite, what using https on .htaccess, wp-config.php and on the network home, such as WP_SITEURL and WP_HOME, the output of get_site_url() will be even if this subsite real (so/and default) site url and home options are: ERGO: get_site_url() is not nearly equal with get_option( ‘siteurl’ )…

Although your .htaccess redirect your subsite (what have http on own siteurl and home options) to https, and this will work fine, but will cause mixed content issue on your site, so than your network home have a link what shows to your subsite, your SSL will not work properly and to you need to correct this bad links in your database with example Better Search Replace plugin…

When I used get_option( ‘home’ ); this gives the REAL value of the home url option unlikely get_site_url().

Finally the if ( $xsiteurl != $ssladdress ) takes care of it that code dont running repeatedly (see in the wordpress codex link), so this safe…

The last “fly in the ointment”, this code it only runs out on a site, if someone open the site (even wp admin, even the front-end)… so the new subsites default siteurl and home options they will remain http, and this code only rewrite this defaults after the code run out… (This maybe can cause mixed content problems if you creating a new subsite, and without that first open it this site’s back or front-end, broadcasting posts on this from other subsites… )

postscript: I am only web designer and just now learning what php, If you now something bad with this code, please write it down.

Read more here:: SOLVED: update_option: siteurl and home in multisite subsites to https://

Leave a Reply

Your email address will not be published. Required fields are marked *