WordPress at a glance

admin_url() WP 2.6.0

Retrieves the URL to the admin area for the current site. Takes into account protocols (http and https).

To get a link to the network admin panel page, use the network_admin_url() function.

Works based on: get_admin_url()
✈ 1 time = 0.001915s = very slow | 50000 times = 2.76s = fast PHP 7.1.2, WP 4.7.4

No Hooks.

Return

String. Admin URL link with optional path appended.

Usage

admin_url( $path, $scheme );
$path(string)
Optional path relative to the admin URL.
Default: ''
$scheme(string)

The scheme (protocol) can be passed to force those schemes.

  • http - specify the Protocol forcibly.
  • https - specify the Protocol forcibly.
  • relative - return relative URL (without domain).

Default: 'admin'

Examples

#1 Demonstration of what the function retrieve

The Protocol will be changed automatically if necessary.

$url = admin_url();
echo $url; //> http://example.com/wp-admin/

#2 Get a link to a specific admin page

Posts > Categories and force https scheme:

$url = admin_url( 'edit-tags.php?taxonomy=category', 'https' );
echo $url; //> https://site.com/wp-admin/edit-tags.php?taxonomy=category

Code of admin_url: wp-includes/link-template.php VER 4.9.8

<?php
function admin_url( $path = '', $scheme = 'admin' ) {
	return get_admin_url( null, $path, $scheme );
}

Related Functions

From tag: Link (URL)

More from category: Site Options (settings)

More from Template Tags: Links (URL)

No comments
    Hello, !     Log In . Register