WordPress get_admin_url() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Returns a URL

Definition

In WordPress, get_admin_url() returns the URL of the admin area (wp-admin) for a site. You can add a path to point to one admin page.

It is useful when you build a link to a settings page or the dashboard. The blog ID is for multisite networks. On a normal site you can leave it empty, or use the shorter admin_url().

Syntax

Return the URL, then print it with esc_url().

WordPress
<?php echo esc_url( get_admin_url() ); ?>
CallWhat it does
get_admin_url()The admin URL of the current site.
get_admin_url( null, 'themes.php' )The URL of the Themes screen.
get_admin_url( 2 )The admin URL of the site with ID 2 on a multisite.

It returns a string. Use esc_url() when you print it inside HTML.

Full declaration
WordPress
get_admin_url( int|null $blog_id = null, string $path = '', string $scheme = 'admin' ): string

Parameters

ParameterDescription
$blog_idint|null. The site ID on a multisite. Default is null, which means the current site.
$pathstring. A path inside wp-admin, such as options-general.php. Default is empty.
$schemestring. How to build the URL: admin, http, or https. Default is admin.

Return Value

Return ValueDescription
stringThe admin URL. It ends with a slash when no path is given.

WordPress Examples

Three short examples. Each one shows the code and what it prints or does.

Example 1 — Get the dashboard URL

Call it with no arguments to get the admin home.

WordPress
<?php
echo esc_url( get_admin_url() );

How It Works

  1. get_admin_url() builds the admin address of the current site.
  2. esc_url() makes it safe to print.
  3. The result ends with /wp-admin/.

Example 2 — Link to a specific admin page

Pass a path as the second argument. Use null for the blog ID.

WordPress
<?php
echo esc_url( get_admin_url( null, 'options-general.php' ) );

How It Works

  1. null means the current site.
  2. options-general.php is the General Settings screen.
  3. The path is added after wp-admin/.

Example 3 — Show a link only to admins

Build a link in a template and show it only to users who can use it.

WordPress
<?php
if ( current_user_can( 'manage_options' ) ) {
  $url = get_admin_url( null, 'themes.php' );
  echo '<a href="' . esc_url( $url ) . '">Change theme</a>';
}

How It Works

  1. current_user_can() checks the permission.
  2. get_admin_url() returns the Themes screen URL.
  3. Visitors and low-level users see nothing.

Frequently Asked Questions

It returns the URL of the wp-admin area for a site, with an optional path added to it.
admin_url() is the short version for the current site. get_admin_url() also lets you choose a site on a multisite network.
No. It returns a string. Use echo with esc_url() to print it.
Yes. Pass the page file as the path, for example admin.php?page=my-plugin.
It is for multisite. On a normal site leave it as null.

Next: get_attachment_link()

Return the URL of an attachment page (image or file page).

get_attachment_link() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

17 people found this page helpful