Skip to content

Instantly share code, notes, and snippets.

@tazziedave
Forked from andrezrv/get-admin-path.php
Last active October 14, 2018 10:17
Show Gist options
  • Save tazziedave/72e03cecd0cd756785e0f28f652f7d8c to your computer and use it in GitHub Desktop.
Save tazziedave/72e03cecd0cd756785e0f28f652f7d8c 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.
$blogUrl = preg_replace("(^https?://)", "", get_bloginfo( 'url' ));
$adminUrl = preg_replace("(^https?://)", "", get_admin_url());
$admin_path = str_replace( $blogUrl . '/', ABSPATH, $adminUrl);
// 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
Author

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

@Obroten54
Copy link

And you can use trailingslashit(ABSPATH)

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