Skip to content

Instantly share code, notes, and snippets.

@arungpisyadi
Created August 11, 2021 05:24
Show Gist options
  • Save arungpisyadi/40f04c9faff93668e50e6813f040f385 to your computer and use it in GitHub Desktop.
Save arungpisyadi/40f04c9faff93668e50e6813f040f385 to your computer and use it in GitHub Desktop.
A script to allow dynamic site_url and home_url.
<?php
if (!defined('ABSPATH')){
define('ABSPATH', dirname(__FILE__) . '/');
}
$main_domain = get_site_url();
$port = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://';
$main_domain = str_replace($port, '', $main_domain);
// var_dump($main_domain);
$viewed_domain = $_SERVER['HTTP_HOST'];
// var_dump($viewed_domain);
$currentpath = preg_replace('@/+$@', '', dirname($_SERVER['SCRIPT_NAME']));
$currentpath = preg_replace('/\/wp.+/', '', $currentpath);
// var_dump($currentpath); exit;
$_url = $port.$viewed_domain.$currentpath;
define('WP_HOME', $_url);
define('WP_SITEURL', $_url);
define('WP_CONTENT_URL', $_url . '/wp-content');
define('WP_PLUGIN_URL', $_url . '/wp-content/plugins');
define('DOMAIN_CURRENT_SITE', $_url);
@define('ADMIN_COOKIE_PATH', './');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment