WordPress get domain

There are times when you only want to use your domain to show in your footer, for example, or use it as a dynamic logo.

In order to obtain the domain you need your site url and then retrieve the protocols here. You can do this in the following ways:

function get_domain() {
   $protocols = array( 'http://', 'https://', 'http://www.', 'https://www.', 'www.' );
   return str_replace( $protocols, '', site_url() );

The reason I use site_url() and not home_url() can you read in this article:

Difference between site url and home url

Robbert Vermeulen

Need help from a WordPress expert?

I would love to hear about your project and how I can help you achieve your goals