Relative or dynamic site url possible?

I usually just avoid the issue entirely every time I create a new wordpress site:

define('WP_HOME', "https://wordpress.stackexchange.com/");
define('WP_SITEURL', "https://wordpress.stackexchange.com/");

will cause wordpress to use root-relative urls for everything. Makes site migrations to other domains far easier. Ofc, if you access your site using a folder (eg. “http://<domain>/blog“) you could change them to:

define('WP_HOME', '/blog/');
define('WP_SITEURL', '/blog/');

For existing sites, make sure the database and any theme/plugin files are free from absolute urls generate by wordpress using the old WP_HOME and WP_SITEURL values.

EDIT: just to clarify, you add these defines to your wp-config.php.

Leave a Comment