The get_clean_basedomain() WordPress PHP function retrieves the base domain of a network.
Usage
To use the get_clean_basedomain() function, simply call the function and store the result in a variable.
$base_domain = get_clean_basedomain(); echo $base_domain; // Output: example.com
Parameters
- None
More information
See WordPress Developer Resources: get_clean_basedomain
Examples
Display Base Domain
This code displays the base domain of the network.
$base_domain = get_clean_basedomain(); echo "The base domain is: " . $base_domain;
Create a Subdomain
This code creates a subdomain by appending a string to the base domain.
$base_domain = get_clean_basedomain(); $subdomain = "blog." . $base_domain; echo "The subdomain is: " . $subdomain;
Generate a Link to a Subpage
This code generates a link to a subpage on the base domain.
$base_domain = get_clean_basedomain(); $subpage = "/contact-us"; $link = "https://" . $base_domain . $subpage; echo "Link to the contact page: " . $link;
Check If Current Domain Matches Base Domain
This code checks if the current domain matches the base domain.
$current_domain = $_SERVER['HTTP_HOST']; $base_domain = get_clean_basedomain(); if ($current_domain === $base_domain) { echo "You are on the base domain!"; } else { echo "You are not on the base domain!"; }
Add WWW to Base Domain
This code adds “www” to the base domain and displays it.
$base_domain = get_clean_basedomain(); $www_domain = "www." . $base_domain; echo "The www version of the base domain is: " . $www_domain;