I host quite a few blogs on my network (WordPress Multisite) and have their static content served via a common CDN, by simply setting the wp-content directory URL in wp-config.php like so:
# http://codex.wordpress.org/Editing_wp-config.php#Moving_wp-content_folder
define( 'WP_CONTENT_URL', 'http://abcdefghijk.cloudfront.net/wp-content' );
Now all static content (images, css, js, etc.) in wp-content directory, for all sites, is served via the common CDN.
The problem is, I need to use a different CDN/URL for wp-content directory for some sub-sites in the network.
So, the question is:
-
Is it possible to set different
WP_CONTENT_URL
values for different sub-sites in wp-config.php? -
If (1) isn’t possible, is it possible to define
WP_CONTENT_URL
in functions.php instead? If yes, then is it possible to set differentWP_CONTENT_URL
values for different sub-sites in functions.php?
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 –
$_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 functionwp_plugin_directory_constants()
which is called before the first hook for pluginsmuplugins_loaded
. So, the only option to define it onwp-config.php
file.