What’s WP_SITEURL?
WP_SITEURL is used to define WordPress address (URL).
The address you define in WP_SITEURL, that’s where your WordPress core files live.
Basically it’s your WordPress root folder on your web host. So when you define WP_SITEURL, you need to include the http:// part too.
When you copy paste an URL, a trailing slash(/) will be included so if you copy and paste URL in the wp-config.php file, make sure to remove the trailing slash(/) at the end.
WP_SITEURL vs wp_options table value for siteurl
If you don’t have any value set in wp-config.php file, WordPress checks for it in the wp_options table.
If you set a WP_SITEURL in wp-config.php file, it’ll override the wp_options table value for siteurl.
Defining WP_SITEURL helps improve WordPress performance since your site needs to make a fewer database call and can easily find the siteurl from the wp-config.php file.
In case you want to change the siteurl from database using WP_SITEURL, you need to use RELOCATE constant.
How to define WP_SITEURL?
Use this line of code to define WP_SITEURL:
define( 'WP_SITEURL', 'http://yogeshchauhan.com' );
How to define WP_SITEURL dynamically?
You can dynamically set WP_SITEURL based on $_SERVER[‘HTTP_HOST’].
define( 'WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/path/to/wp-directory' );
You can dynamically set WP_SITEURL based on $_SERVER[‘SERVER_NAME’] too.
define( 'WP_SITEURL', 'http://' . $_SERVER['SERVER_NAME'] . '/path/to/wp-directory' );
HTTP_HOST vs SERVER_NAME
PHP used HTTP HOST Header value in the request to create HTTP_HOST dynamically. That might cause a problem by possibly creating a room for file inclusion vulnerabilities.
SERVER_NAME can be created dynamically too but if you configure Apache server and set UseCanonicalName “on”, then SERVER_NAME won’t be created dynamically anymore and SERVER_NAME value will be set by the server configuration.
It is safer to use SERVER_NAME over HTTP_HOST when UseCanonicalName is set “on” in Apache configurations and SERVER_NAME is not allowed to be created dynamically.
home_url HTTP_HOST server SERVER_NAME url WP_SITEURL