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

Leave a reply

Feel free to ask questions or make comments.

Comments

    No comments yet..