WordPress at a glance

get_admin_url() WP 3.0.0

Retrieves the URL to the site admin area.

This function works the same as admin_url() but has an additional parameter $blog_id for WordPress multisite.

Works based on: get_site_url()
Basis of: admin_url()
1 time = 0.001866s = very slow | 50000 times = 2.45s = fast | PHP 7.2.16, WP 5.2.2
Hooks from the function

String. Admin URL link with optional path appended.


get_admin_url( $blog_id, $path, $scheme );
Blog (site) ID.
Default: null (current site)
Path relative to the admin URL.
Default: ''

The protocol to use. Accepts:

relative   — returns relative URL (without domain).
login      — the Protocol of the login page
null       — the current protocol of the website is_ssl()

See set_url_scheme() for more information.

Default: 'admin', which obeys force_ssl_admin() and is_ssl()


#1 Basic usage

The scheme (protocol) will be changed automatically to https when the website will support it.

$url = get_admin_url();
echo $url;

// Output: http://www.example.com/wp-admin/

#2 Get the link to edit categories page, and set up the scheme as https

echo get_admin_url( null, 'edit-tags.php?taxonomy=category', 'https' );

// Output: https://www.example.com/wp-admin/edit-tags.php?taxonomy=category

#3 Get the link to the specific blog (2 - blog2)

$url = get_admin_url(2);
echo $url;

// Output: https://www.blog2.example.com/wp-admin/


Since 3.0.0 Introduced.

Code of get_admin_url() WP 5.6

function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' ) {
	$url = get_site_url( $blog_id, 'wp-admin/', $scheme );

	if ( $path && is_string( $path ) ) {
		$url .= ltrim( $path, '/' );

	 * Filters the admin area URL.
	 * @since 2.8.0
	 * @param string   $url     The complete admin area URL including scheme and path.
	 * @param string   $path    Path relative to the admin area URL. Blank string if no path is specified.
	 * @param int|null $blog_id Site ID, or null for the current site.
	return apply_filters( 'admin_url', $url, $path, $blog_id );

From category: Admin Menu

More from Template Tags: Links (URL)

No comments
    Log In