Skip to content

Instantly share code, notes, and snippets.

@devfreddy
Last active February 10, 2016 16:19
Show Gist options
  • Save devfreddy/dc6796231dc003aaee99 to your computer and use it in GitHub Desktop.
Save devfreddy/dc6796231dc003aaee99 to your computer and use it in GitHub Desktop.
Wordpress dynamically set site url for local development
<?php
/*
* Still requires the nginx server_name to be set to one of these
* For names, still requires hosts file to be set
* Just updates one thing for you automatically so if your local ip changes you don't have to change so many things
*
*/
$ip = $_SERVER['SERVER_ADDR'];
$identifiers = array( $_SERVER['HTTP_HOST'], $_SERVER['REMOTE_ADDR'], $_SERVER['SERVER_NAME'] );
$aliases = array('local.site.org', $ip . '.xip.io', $ip, '127.0.0.1', '127.0.0.1.xip.io');
foreach($identifiers as $key => $identity){
if(!empty($identity) && in_array($identity, $aliases)){
define('WP_HOME', 'https://' . $identity);
define('WP_SITEURL', 'https://' . $identity);
error_log("Setting to: " . WP_HOME);
break;
}
}
/*
* Nginx server block for the secure beta site
* Add these to the server name:
* 192.168.1.123.xip.io
* 192.168.1.123
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment