Skip to content

Instantly share code, notes, and snippets.

@evanre
Created July 2, 2016 11:25
Show Gist options
  • Save evanre/87837fb98490f778ae8c37e2919a9f1d to your computer and use it in GitHub Desktop.
Save evanre/87837fb98490f778ae8c37e2919a9f1d to your computer and use it in GitHub Desktop.
WordPress: Set WordPress site URL in the config file instead of the database
<?php
// WordPress stores the site URL in the database by default (which I have never
// understood), and it's a pain to have to type out the UPDATE SQL or search in
// phpMyAdmin to change it. This is a simple way to put the URL into
// wp-config.php instead.
// Note that you will still need to update any URLs that appear in the content,
// especially when you copy a database from a development site to production:
// https://gist.github.com/davejamesmiller/a8733a3fbb17e0ff0fb5
// Add these lines to wp-config.php:
define('WP_SITEURL', 'http://www.domain.com');
define('WP_HOME', 'http://www.domain.com');
// Or add appropriate logic so it works on all servers:
if ($_SERVER['HTTP_HOST'] == 'dev.domain.com') {
define('WP_SITEURL', 'http://dev.domain.com');
define('WP_HOME', 'http://dev.domain.com');
} else {
define('WP_SITEURL', 'http://www.domain.com');
define('WP_HOME', 'http://www.domain.com');
}
// Or you can use the current hostname automatically - but note that WordPress
// won't be able to redirect to the canonical domain for you
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment