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';
    /** etc... **/

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 );
  • please do not rant in your questions, unless the rant is relevant to th question itself. If you do not understand why your question was downvoted the right place to try to figure it out is either at the meta section of the site or at the "the loop" chat room. Commented Mar 1, 2018 at 8:24
  • Possible duplicate of How to set default Site url settings on WORDPRESS multisite?
    – mmm
    Commented Mar 1, 2018 at 8:29
  • You can't set HTTPS by assigning on value to the $_SERVER array element. $_SERVER is dedicated to provide the information, not to set up the server environment. Documentation.
    – Max Yudin
    Commented Mar 1, 2018 at 8:39
  • I refresh my question, the problem maybe in contact with set_url_scheme, but I so far I have not found anything about this... Commented Mar 1, 2018 at 8:51
  • 1
    Please stop editing the question. It's impossible to help you when the question subject gets changed multiple times. When you want to ask a different question, please, start the new one.
    – Max Yudin
    Commented Mar 1, 2018 at 11:31

1 Answer 1



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

AND READ THIS, BEFORE USING: https://codex.wordpress.org/Changing_The_Site_URL#Edit_functions.php

if ( ! is_admin() ) {
   $xsiteurl = get_option( 'home' );
   $find = array( 'http://', 'https://' );
   if ( $find != 'http://' ) {
        $replace = '';
        $pureaddress = str_replace( $find, $replace, $xsiteurl );
        $ssladdress = 'https://' . $pureaddress . '';

        if ( $xsiteurl != $ssladdress  ) {
             update_option( 'siteurl', '' . $ssladdress . '' );
             update_option( 'home', '' . $ssladdress . '' );

Notes: 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 https://subdomain.domain.com even if this subsite real (so/and default) site url and home options are: http://subdomain.domain.com. 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 php, If you know something bad with this code, please write it down.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.