How to retrieve TLD domain for the current website?


WordPress has certain variables like site_url and home_url and paths for things like plugins, themes, uploads, etc… but it seems there is no easy way to display current TLD domain.

This probably requires using PHP preg_replace or something similar but I’m not sure what is the cleanest or most reliable way to generate this snippet?

For example for a WP site installed to a URL like how can you detect the TLD only (and e.g. save it as a variable for use in a PHP script)… it either needs to be aware of a large variety of different TLDs, or at least customizable for different TLD types?

Jesse Nickles 3 months 0 Answers 12 views 0

Leave an answer