get_home_path(): string
Gets the absolute filesystem path to the root of the WordPress installation.
Return
string Full filesystem path to the root of the WordPress installation.
Source
File: wp-admin/includes/file.php
.
View all references
function get_home_path() {
$home = set_url_scheme( get_option( 'home' ), 'http' );
$siteurl = set_url_scheme( get_option( 'siteurl' ), 'http' );
if ( ! empty( $home ) && 0 !== strcasecmp( $home, $siteurl ) ) {
$wp_path_rel_to_home = str_ireplace( $home, '', $siteurl ); /* $siteurl - $home */
$pos = strripos( str_replace( '\\', '/', $_SERVER['SCRIPT_FILENAME'] ), trailingslashit( $wp_path_rel_to_home ) );
$home_path = substr( $_SERVER['SCRIPT_FILENAME'], 0, $pos );
$home_path = trailingslashit( $home_path );
} else {
$home_path = ABSPATH;
}
return str_replace( '\\', '/', $home_path );
}
Changelog
Version | Description |
---|---|
1.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
Default Usage
Top ↑
Feedback
It’s also not available on the frontpage, it’s available only from wp-admin (backend). You should check if is_admin() otherwise you’ll get “Fatal error: Uncaught Error: Call to undefined function get_home_path()”. — By dlawp —
Apparently this doesn’t return the correct results when using WP_CLI.