Introduction to network_site_url() function in WordPress
The network_site_url()
function is one of the important and commonly used functions in WordPress that helps you retrieve the URL of the network site. In other words, this function allows you to access the original site URL of the WordPress network. Usually, when developing multisite websites, it is necessary to have the URL of the main site, and this function comes in handy in that case.
You might have a previous question about the difference between network_site_url()
and other functions like site_url()
: while site_url()
retrieves the URL of a specific site, network_site_url()
fetches the URL of the main network site. This feature is especially important in large and complex projects that involve multiple sites.
You can use this function when you need the network site URL. For example, if you have a plugin or theme that requires access to the main site resources, you can benefit from this function. It also supports backward compatibility from multiple sites, making its usage quite handy!
Using network_site_url()
is very straightforward and simply requires calling the function whenever you need it.
Code Example
$network_url = network_site_url();
echo $network_url;
Code Explanation
In this section, we explain the code line by line:
$network_url = network_site_url();
This line calls thenetwork_site_url()
function and stores the result in the variable$network_url
.echo $network_url;
In this line, the variable$network_url
, which contains the URL of the network site, is sent to the output for viewing.