Using WordPress ‘get_blogaddress_by_domain()’ PHP function

The get_blogaddress_by_domain() WordPress PHP function retrieves a full blog URL, given a domain and a path.

Usage

$blog_url = get_blogaddress_by_domain( 'example.com', '/blog' );
echo $blog_url; // Output: https://example.com/blog

Parameters

  • $domain (string) – The domain of the blog you want to retrieve the URL for.
  • $path (string) – The path of the blog on the domain.

More information

See WordPress Developer Resources: get_blogaddress_by_domain()

Examples

Get the blog address for a subdomain

Get the blog address for a blog hosted on a subdomain.

$blog_url = get_blogaddress_by_domain( 'blog.example.com', '/' );
echo $blog_url; // Output: https://blog.example.com/

Get the blog address for a subfolder

Get the blog address for a blog hosted in a subfolder.

$blog_url = get_blogaddress_by_domain( 'example.com', '/my-blog' );
echo $blog_url; // Output: https://example.com/my-blog

Get the blog address for a custom domain

Get the blog address for a blog hosted on a custom domain.

$blog_url = get_blogaddress_by_domain( 'mycustomdomain.com', '/' );
echo $blog_url; // Output: https://mycustomdomain.com/

Get the blog address with a specific path

Get the blog address for a blog hosted on a domain with a specific path.

$blog_url = get_blogaddress_by_domain( 'example.com', '/2023/05/my-article' );
echo $blog_url; // Output: https://example.com/2023/05/my-article

Get the blog address for a subdomain and subfolder

Get the blog address for a blog hosted on a subdomain and a subfolder.

$blog_url = get_blogaddress_by_domain( 'sub.example.com', '/my-blog' );
echo $blog_url; // Output: https://sub.example.com/my-blog