wppaste
WordPress

admin_url( string $path = '', string $scheme = 'admin' ): string

Since
2.6.0
Source
wp-includes/link-template.php:3564

Get the URL of the WordPress admin area with admin_url(), optionally appending a path such as 'options-general.php' with the correct scheme. The default 'admin' scheme honors force_ssl_admin() and is_ssl(), so links keep working when the dashboard is forced to https.

Retrieves the URL to the admin area for the current site.

Parameters

$pathstringoptional
Path relative to the admin URL. Default empty.Default: ''
$schemestringoptional
The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes.Default: 'admin'

Return

string
Admin URL link with optional path appended.

Examples

Every example is editable and runs in a real WordPress booted in your browser by WordPress Playground. Press Run, then edit the code: clicking away re-runs it. Nothing is sent anywhere until you do.

Build dashboard links from admin_url() plus add_query_arg() instead of hard-coding /wp-admin/, which breaks on subdirectory installs.

$settings_url = add_query_arg(
	array( 'page' => 'myplugin' ),
	admin_url( 'options-general.php' )
);

printf(
	'<a href="%s">%s</a>',
	esc_url( $settings_url ),
	esc_html__( 'Plugin settings', 'myplugin' )
);

admin_url() always targets the current site. On multisite, use network_admin_url() for network admin pages or get_admin_url( $blog_id ) to link into another site's dashboard.

Uses · 1

Used by · 50

Show all 50

Source

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

History

Introduced in 2.6.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/link-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.