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

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


Parameters

$path

(string) (Optional) Path relative to the admin URL. Default 'admin'.

Default value: ''

$scheme

(string) (Optional) 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 value: 'admin'


Top ↑

Return

(string) Admin URL link with optional path appended.


Top ↑

Source

File: wp-includes/link-template.php

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


Top ↑

Changelog

Changelog
Version Description
2.6.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Codex

    Examples

    <?php echo admin_url(); ?>

    Output: http://example.com/wp-admin/ (or https protocol when appropriate)

    // Generate URL to admin's "Categories" page, and force https
    <?php echo admin_url( 'edit-tags.php?taxonomy=category', 'https' ); ?>

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

  2. Skip to note 3 content
    Contributed by xandercalvert

    If you are looking for the post edit url for admin end and you have the post id (suppose $post_id) with you, then you can use the following code for getting the url.

    $post_id = 1731; // For example
    $post_url = add_query_arg( array( 
    	'post' => $post_id, 
    	'action' => 'edit', 
    ), admin_url( 'post.php' ) );
    
    // returns http://example.com/wp-admin/post.php?post=1731&action=edit
    

You must log in before being able to contribute a note or feedback.