Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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;
}
@ElawadyNet

This comment has been minimized.

Copy link

@ElawadyNet ElawadyNet commented Sep 15, 2015

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

@tazziedave

This comment has been minimized.

Copy link

@tazziedave tazziedave commented Jan 12, 2017

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

This comment has been minimized.

Copy link

@Tofandel 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