By default wordpress only allows you to access from either domain name or IP address, which makes remote management somewhat challenge and hassle to complete, for example when using my VPN from remote location, the website due to pre-launch status, it is not available on public web, so I will need local LAN IP to access the site at the same time.
1. Set your server address to LAN IP
2. Edit wp-config.php
Add the following script after define ( ‘ABSPATH’, _DIR_ ….
/**
* get home url from absolute path
* @return string url to main site
* hello@lafif.me
*/
function get_dynamic_home_url(){
$base_dir = ABSPATH; // Absolute path
$doc_root = preg_replace("!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME']);
$base_url = preg_replace("!^${doc_root}!", '', $base_dir);
$protocol = empty($_SERVER['HTTPS']) ? 'http' : 'https';
$port = $_SERVER['SERVER_PORT'];
$disp_port = ($protocol == 'http' && $port == 80 || $protocol == 'https' && $port == 443) ? '' : ":$port";
$domain = $_SERVER['SERVER_NAME'];
$home_url = "${protocol}://${domain}${disp_port}${base_url}";
return $home_url;
}
$url = get_dynamic_home_url();
define('WP_SITEURL', $url);
define('WP_HOME', $url);
3. Now you can access from Domain Name and LAN address.