Using WordPress ‘get_admin_url()’ PHP function

The get_admin_url() WordPress PHP function retrieves the URL to the admin area for a given site.

Usage

get_admin_url( $blog_id, $path, $scheme )

Custom Example:

// Get the admin URL for the current site
$admin_url = get_admin_url();
echo $admin_url; // Output: "https://example.com/wp-admin/"

Parameters

  • $blog_id int|null Optional – Site ID. Default null (current site).
  • $path string Optional – Path relative to the admin URL. Default: ”.
  • $scheme string Optional – The scheme to use. Accepts ‘http’ or ‘https’, to force those schemes. Default ‘admin’, which obeys force_ssl_admin() and is_ssl(). Default: ‘admin’.

More information

See WordPress Developer Resources: get_admin_url()

Examples

Get the admin URL for a specific site

Get the admin URL for site with the ID 2:

$admin_url = get_admin_url(2);
echo $admin_url; // Output: "https://example.com/site2/wp-admin/"

Get the admin URL with a custom path

Get the admin URL for the current site with a custom path to the plugins page:

$admin_url = get_admin_url(null, 'plugins.php');
echo $admin_url; // Output: "https://example.com/wp-admin/plugins.php"

Force the admin URL scheme to HTTP

Force the admin URL to use the ‘http’ scheme:

$admin_url = get_admin_url(null, '', 'http');
echo $admin_url; // Output: "http://example.com/wp-admin/"

Force the admin URL scheme to HTTPS

Force the admin URL to use the ‘https’ scheme:

$admin_url = get_admin_url(null, '', 'https');
echo $admin_url; // Output: "https://example.com/wp-admin/"

Get the admin URL for a specific site with a custom path

Get the admin URL for site with the ID 3 and a custom path to the themes page:

$admin_url = get_admin_url(3, 'themes.php');
echo $admin_url; // Output: "https://example.com/site3/wp-admin/themes.php"