Skip to content

Instantly share code, notes, and snippets.

@andrezrv
Created October 30, 2014 21:18
Show Gist options
  • Save andrezrv/f7a083627f3bd89c3d9e to your computer and use it in GitHub Desktop.
Save andrezrv/f7a083627f3bd89c3d9e to your computer and use it in GitHub Desktop.
Obtain path to wp-admin directory in WordPress.
<?php
/**
* Obtain the path to the admin directory.
*
* @return string
*/
function my_plugin_get_admin_path() {
// Replace the site base URL with the absolute path to its installation directory.
$admin_path = str_replace( get_bloginfo( 'url' ) . '/', ABSPATH, get_admin_url() );
// Make it filterable, so other plugins can hook into it.
$admin_path = apply_filters( 'my_plugin_get_admin_path', $admin_path );
return $admin_path;
}
@tazziedave
Copy link

Forked to modify so that if url's contain a mix of http and https, function still works.

$admin_directory = ABSPATH.'/wp-admin/';

Only if admin directory is left as standard. It might be changed as a security measure.

@Tofandel
Copy link

Tofandel commented Aug 2, 2018

Nope it might not, it's hardcoded as well in the core and in so much stuff, you cannot rename or move this directory, not the same for other dirs like WP_CONTENT_DIR or WP_PLUGIN_DIR which can be changed and thus have a defined constant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment