get_admin_url()
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.
Uses: get_site_url()
Used By: admin_url()
1 time — 0.001866 sec (very slow) | 50000 times — 2.45 sec (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. |
get_admin_url() get admin url code WP 6.7.1
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 * @since 5.8.0 The `$scheme` parameter was added. * * @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. * @param string|null $scheme The scheme to use. Accepts 'http', 'https', * 'admin', or null. Default 'admin', which obeys force_ssl_admin() and is_ssl(). */ return apply_filters( 'admin_url', $url, $path, $blog_id, $scheme ); }