Skip to content

Instantly share code, notes, and snippets.

@maxkostinevich
Created August 21, 2015 08:40
Show Gist options
  • Save maxkostinevich/0e4c662b9beb10a89d74 to your computer and use it in GitHub Desktop.
Save maxkostinevich/0e4c662b9beb10a89d74 to your computer and use it in GitHub Desktop.
Get Website Domain TLD
// Get Website Domain TLD
function get_site_tld($url){
$host = parse_url($url);
preg_match('/(.*?)((\.co)?.[a-z]{2,4})$/i', $host['host'], $m);
$ext = isset($m[2]) ? $m[2]: '';
return $ext; // Domain TLD
}
// For WP just call
get_site_tld( get_site_url() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment