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

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


$path string Optional
Path relative to the admin URL.

Default: ''

$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: 'admin'

Top ↑


string Admin URL link with optional path appended.

Top ↑


File: wp-includes/link-template.php. View all references

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

Top ↑


Version Description
2.6.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Codex


    <?php echo admin_url(); ?>

    Output: (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' ); ?>


  2. Skip to note 2 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
  3. Skip to note 4 content
    Contributed by israelakinola

    Logout Users based on specific capabilities and role

    if ( ! current_user_can( 'edit_posts' ) && ! is_admin() ) {
    	$redirect_url = site_url();
    } else {
    	$redirect_url = '/wp-login.php';
    function wpdocs_redirect_after_logout() {
    	global $redirect_url;
    	wp_safe_redirect( $redirect_url );
    add_action( 'wp_logout', 'wpdocs_redirect_after_logout' );
  4. Skip to note 5 content
    Contributed by Kowsar Hossain

    The presence of a leading slash in the path doesn’t affect the output, as it will be internally removed. Thus, both calls to admin_url() will yield the same result:

    admin_url( 'test' );  // returns
    admin_url( '/test' ); // returns

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