7

Except for the $blog_id parameter (which is only allowed in the get_admin_url function), what is the difference between admin_url and get_admin_url?

0

3 Answers 3

5

The admin_url() function retrieves the URL to the admin area for your current site. You needn't give the blog id for your current site. You can use this function if you aren't running WordPress multisite. And use the get_admin_url() function to get a specific site URL in the multisite admin.

4

For single site installation:

Technically, except the $blog_id parameter, there isn't any difference at all.

admin_url function uses get_admin_url function internally with $blog_id parameter set to null. This is the source CODE of admin_url function:

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

And this is the function signature of get_admin_url function:

function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' )

So basically, calling admin_url( $path, $scheme ) is the same as calling get_admin_url( null, $path, $scheme ).

For multisite installation:

Since admin_url() doesn't support the $blog_id parameter, it's always used to get the Admin URL of the default blog (i.e. the current site you are accessing). However, if your WordPress is a multisite installation, and you need the Admin URL of another site within the same multisite network, then you'll need to use get_admin_url( $blog_id ).

0

As clarified in the old WP references (but not in the new ones), the only difference between the two functions is that get_admin_url allows the management of multi-site, thanks to the $blog_id parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.