2

Is there a better way of retrieving the path of admin.php and the url of wp-admin.css?

What I can think of is:

$adminphppath = ABSPATH . '\wp-admin\admin.php';
$admincssurl = get_bloginfo('wpurl') . '/wp-admin/css/wp-admin.css";

But, some may be changing the admin path for security. So I need a more reliable way.

[Edit] I need the system path for admin.php, not url. Because I need to include it.

3
  • You cannot change the wp-admin folder name. You can rewrite it url wise but it ain't going to make anything more secure.
    – Wyck
    Commented Aug 20, 2012 at 3:30
  • So is ABSPATH the most reliable way?
    – Teno
    Commented Aug 20, 2012 at 5:17
  • yes, yes it is.
    – Wyck
    Commented Aug 20, 2012 at 5:31

2 Answers 2

7

You can use admin_url() function for wp-admin.css file and ABSPATH for admin.php.

$admin_php_path = ABSPATH . '/wp-admin/admin.php';
$admin_css_url = admin_url( 'css/wp-admin.css' );
2
  • For the css file it works thanks but for admin.php, actually I need to use include() so I need the system path, not the url. If I include with url, I get Warning: require() [function.require]: http:// wrapper is disabled in the server configuration by allow_url_include=0
    – Teno
    Commented Aug 20, 2012 at 2:59
  • O, sorry about that. admin_url() will return URL which is useless with require or include, so as @Wyck said you should use ABSPATH. Updated answer.
    – Mamaduka
    Commented Aug 20, 2012 at 7:43
1

Old question I know, but this accounts for installs where wp-admin is not the admin directory

$admin_abspath = str_replace( site_url(), ABSPATH, admin_url() );
$admin_php_path = $admin_abspath . '/wp-admin/admin.php';
1
  • Close, but results in duplicate slashes right at wp-admin.... (as in /my/path/to//wp-admin) Commented Nov 3, 2016 at 21:37

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.