PHP Code Not Working – Display Domain Name
-
I have the following PHP Code as a PHP Snippet:
function display_domain_name() {
// Get the site URL
$site_url = get_site_url();
// Parse the URL to get the host
$parsed_url = parse_url($site_url);
$domain = $parsed_url['host'];
// Return the domain
return $domain;
}
// Print domain name
echo display_domain_name();I am configuring this code as a Shortcode.
For some reason this is not working properly. If I use the shortcode once in the page, it displays the value correctly (domain name – e.g.
example.com). If I use the shortcode more than once in the page, the page breaks (error 500).I have tried to remove the
echoas well, but in that case, it doesn’t display anything in the page where the shortcode is inserted once, and in the page where the shortcode is inserted more than once, the page still breaks (error 500).Any idea why this is happening and how to fix it? Can the same shortcode be inserted multiple times in the same page?
- This topic was modified 1 year, 10 months ago by .
The topic ‘PHP Code Not Working – Display Domain Name’ is closed to new replies.