Yogesh Chauhan's Blog

WordPress: How to set WP_SITEURL?

in WordPress on December 28, 2021


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' );


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.

Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
PostgreSQL BETWEENPostgresHow to create a flip effect with CSS?CSSHow to force your website to load securely with an .htaccess file?MiscellaneousHow to create HTML elements with ID and class using JavaScript?HTMLHow to insert Bootstrap 4 in Angular 9 app?AngularHow SCSS (Sass) finds a module without a file extension?SCSS