TransWikia.com

What's the difference between admin_url() and get_admin_url() functions?

WordPress Development Asked by Juri Rudi on January 6, 2021

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?

3 Answers

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.

Correct answer by Eh Jewel on January 6, 2021

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 CODE of admin_url function:

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

Now, check the function signature of get_admin_url:

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

So basically, calling admin_url() is the same as calling get_admin_url() unless you are in a multisite installation.

So, the only realistic difference is that, admin_url() doesn't support the $blog_id parameter, so it's always used to get the admin url of the default blog (i.e. the current site you are accessing). That's why you'll need get_admin_url( $blog_id ) in a multisite installation (to get another site's admin URL within the same multisite network).

Answered by Fayaz on January 6, 2021

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.

Answered by Juri Rudi on January 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP