1

Why does WordPress store 'siteurl' and 'home' in the database?

It's driving me crazy because I develop locally, deploy to a staging site, AND to a production site, so that's two-three times I have to go through the database to replace all those values. It seems kind of backwards to store this value, when you can just get it from the URL the site is running from, so I must be missing some context or something.

I'd love some solutions where I don't have to search and replace every single time I deploy changes. I want to be able to just copy files and the database and have it work, like literally every other system I use. (Drupal, Laravel, Rails)

2

Since you mention multiple environments you can manually define the site URL within your wp-config.php file

define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/path/to/wordpress');
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/path/to/wordpress');

Keep in mind that it will override what you have set in your options table. As detailed in the documentation:

Setting this value in wp-config.php overrides the wp_options table value for siteurl and overrides the WordPress address (URL) field in the Administration > Settings > General panel when logging in using wp-login.php. It will not update your Home url.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.