Home WordPress Links Functions get_admin_url() WordPress get_admin_url() Function 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().
<?php echo esc_url( get_admin_url() ); ?> Call What 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 get_admin_url( int|null $blog_id = null, string $path = '', string $scheme = 'admin' ): string Parameters Parameter Description $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 Value Description string The 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.
1. Get the dashboard URL 2. Link to a specific admin page 3. Show a link only to admins Example 1 — Get the dashboard URL Call it with no arguments to get the admin home.
<?php
echo esc_url( get_admin_url() ); https://example.com/wp-admin/ How It Works get_admin_url() builds the admin address of the current site.esc_url() makes it safe to print.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.
<?php
echo esc_url( get_admin_url( null, 'options-general.php' ) ); https://example.com/wp-admin/options-general.php How It Works null means the current site.options-general.php is the General Settings screen.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.
<?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 current_user_can() checks the permission.get_admin_url() returns the Themes screen URL.Visitors and low-level users see nothing. Frequently Asked Questions What does get_admin_url() do? It returns the URL of the wp-admin area for a site, with an optional path added to it.
What is the difference between get_admin_url() and admin_url()? admin_url() is the short version for the current site. get_admin_url() also lets you choose a site on a multisite network.
Does it print the URL? No. It returns a string. Use echo with esc_url() to print it.
Can I use it for a custom admin page? Yes. Pass the page file as the path, for example admin.php?page=my-plugin.
What is the blog ID for? It is for multisite. On a normal site leave it as null.
About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion