How WordPress get the base URL
-
Assume our base URL is
example.com.$_SERVER['SERVER_NAME']is enough to get this.But if it’s in a local development environment ( LDE ) like Xampp, the base URL is
localhost/examplewhere theexampleis the WordPress folder name.$_SERVER['SERVER_NAME']is already not capable as it only returnslocalhost. Butget_option('siteurl')is still capable of returninglocalhost/example.My question is how WordPress know the base URL is
localhost/example, as$_SERVER['SERVER_NAME']only returnslocalhost.Because if I develop a plugin and I use
$_SERVER['SERVER_NAME'], apparently it not gonna work in LDE.You might ask why not just use
get_option('siteurl')then, because I wanna learn how WordPress get that.
The topic ‘How WordPress get the base URL’ is closed to new replies.