Multisite, Domain Mapping - use of WP_HOME constant when configuring WP_CONTENT_URL

Hi there,

I spent a bit of time researching this but I end up opening a topic here because I’m … confused

I have a Multisite install w/ Bedrock and a Sage 8 theme where one of the sites has a domain mapped to it.

I noticed that even on this domain mapped site the urls for the assets where using the domain I entered for WP_HOME constant in the .env file

which would cause a main problem of fonts not being loaded because of a cross-domain issue (which could be solved with CORS headers I guess - but that would not address the main issue I feel)

I tracked the issue down to the fact that in WP_CONTENT_URL is setup using WP_HOME . CONTENT_DIR

when it seems like in a multisite install WP_HOME is not used by default

in ms-default-filters.php around line 86

// WP_HOME and WP_SITEURL should not have any effect in MS
remove_filter( 'option_siteurl', '_config_wp_siteurl' );
remove_filter( 'option_home',    '_config_wp_home'    );

I guess I could either remove the WP_HOME part of the WP_CONTENT_URL or some other work around but I would be really appreciative of some input or leads on how to solve this the best way

thanks in advance

updating this topic with a few possibilities that could be used in the case I describe and hoping to get feedback on the pros of cons of each one by people with more experience on this matter

  • using relative urls by removing the WP_HOME part in the building of WP_CONTENT_URL

define('WP_CONTENT_URL', CONTENT_DIR);

I don’t know if this can have hidden side effects in WP

  • using WP_HOME=http://${HTTP_HOST}

as hinted to in this thread https://github.com/roots/bedrock/issues/224

but this is probably not a good idea due mainly to how this would affect how WP sets canonical urls

  • branching on the current domain and using it to build WP_CONTENT_URL

something like this:

define('HTTP_PROTOCOL', $_SERVER['HTTPS'] ? 'https' : 'http');
if(preg_match("/my-mapped-domain.com/", $_SERVER['HTTP_HOST'])) {
    define('WP_CONTENT_URL', HTTP_PROTOCOL . '://my-mapped-domain.com' . CONTENT_DIR);
}
else {
    define('WP_CONTENT_URL', WP_HOME . CONTENT_DIR);
}

but this also relies on a $_SERVER variable
and would probably need refining

anyways, hoping to get feedback on this even if it’s to say I’m not approaching things correctly

thanks

1 Like