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.

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

String. Admin URL link with optional path appended.

Usage

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

The protocol to use. Accepts:

http
https
relative   — returns relative URL (without domain).
login      — the Protocol of the login page
login_post
admin
rest
rpc
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()

Examples

#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/

Changelog

Since 3.0.0 Introduced.

Code of get admin url: wp-includes/link-template.php WP 5.2.4

<?php
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 );
}

Related Functions

From category: Admin Menu

More from Template Tags: Links (URL)

No comments
    Hello, !     Log In . Register