Skip to content

Instantly share code, notes, and snippets.

@tamimibrahim17
Created April 3, 2017 06:10
Show Gist options
  • Save tamimibrahim17/3062119a5ac05a1b156404928a7d74db to your computer and use it in GitHub Desktop.
Save tamimibrahim17/3062119a5ac05a1b156404928a7d74db 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