Skip to content

Instantly share code, notes, and snippets.

@catzy007
Last active February 22, 2019 10:25
Show Gist options
  • Select an option

  • Save catzy007/b8ae122f34e96c900404be56892558cc to your computer and use it in GitHub Desktop.

Select an option

Save catzy007/b8ae122f34e96c900404be56892558cc to your computer and use it in GitHub Desktop.
wordpress config
/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
/**
* 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['HTTP_HOST'];
$home_url = "${protocol}://${domain}${disp_port}${base_url}";
return $home_url;
}
$url = get_dynamic_home_url();
define('WP_SITEURL', $url);
define('WP_HOME', $url);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment