Different ‘WP_CONTENT_URL’ for different subsites in Multisite setup?

Is it possible to set different WP_CONTENT_URL values for different sub-sites in wp-config.php ?

Ans: Yes it is. If sub sites are installed on sub-domain, An example to define it this way –

define( 'CURRENT_SITE_DOMAIN', $_SERVER['HTTP_HOST'] );

if( 'sub1.domain.com' == CURRENT_SITE_DOMAIN ){
    define( 'WP_CONTENT_URL', 'http://sub1-abcdefghijk.cloudfront.net/wp-content' );
}
elseif( 'sub2.domain.com' == CURRENT_SITE_DOMAIN ){
    define( 'WP_CONTENT_URL', 'http://sub2-abcdefghijk.cloudfront.net/wp-content' );
}
else{
    define( 'WP_CONTENT_URL', 'http://abcdefghijk.cloudfront.net/wp-content' );
}

$_SERVER['HTTP_HOST'] will give you the domain host name, which comes without the protochol name (http[s]://) and without any trailing slash (/)

Is it possible to define WP_CONTENT_URL in functions.php instead? If yes, then is it possible to set different WP_CONTENT_URL values for different sub-sites in functions.php ?

Ans: No it’s not. WP_CONTENT_URL Constant is defined within a function wp_plugin_directory_constants() which is called before the first hook for plugins muplugins_loaded. So, the only option to define it on wp-config.php file.

Leave a Comment