How to get site URL if database is disconnected?

One option is setting the site’s URL in the wp-config.php file itself. This effectively overrides the siteurl option that’s otherwise stored in the database, but it also means you can reference the URL without doing a query.

From the Codex:

It is possible to set the site URL manually in the wp-config.php file.

Add these two lines to your wp-config.php, where “example.com” is the correct location of your site.

define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');

After that, using code in a regular theme that checks the siteurl or home option will pull from the constant rather than the database (hence my note on the override above). But in your default error script, you can reference WP_SITEURL directly to build a redirect URL.

Leave a Comment