Title: get_home_path
Published: April 25, 2014
Last modified: May 20, 2026

---

# get_home_path(): string

## In this article

 * [Return](https://developer.wordpress.org/reference/functions/get_home_path/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_home_path/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_home_path/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_home_path/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_home_path/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_home_path/?output_format=md#wp--skip-link--target)

Gets the absolute filesystem path to the root of the WordPress installation.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_home_path/?output_format=md#return)󠁿

 string Full filesystem path to the root of the WordPress installation.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_home_path/?output_format=md#source)󠁿

    ```php
    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 );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/file.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-admin/includes/file.php#L107)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-admin/includes/file.php#L107-L121)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_home_path/?output_format=md#related)󠁿

| Uses | Description | 
| [set_url_scheme()](https://developer.wordpress.org/reference/functions/set_url_scheme/)`wp-includes/link-template.php` |

Sets the scheme for a URL.

  | 
| [trailingslashit()](https://developer.wordpress.org/reference/functions/trailingslashit/)`wp-includes/formatting.php` |

Appends a trailing slash.

  | 
| [get_option()](https://developer.wordpress.org/reference/functions/get_option/)`wp-includes/option.php` |

Retrieves an option value based on an option name.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/get_home_path/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_home_path/?output_format=md#)

| Used by | Description | 
| [WP_Debug_Data::get_wp_server()](https://developer.wordpress.org/reference/classes/wp_debug_data/get_wp_server/)`wp-admin/includes/class-wp-debug-data.php` |

Gets the WordPress server section of the debug data.

  | 
| [network_step2()](https://developer.wordpress.org/reference/functions/network_step2/)`wp-admin/includes/network.php` |

Prints step 2 for Network installation process.

  | 
| [save_mod_rewrite_rules()](https://developer.wordpress.org/reference/functions/save_mod_rewrite_rules/)`wp-admin/includes/misc.php` |

Updates the htaccess file with the current rules if it is writable.

  | 
| [iis7_save_url_rewrite_rules()](https://developer.wordpress.org/reference/functions/iis7_save_url_rewrite_rules/)`wp-admin/includes/misc.php` |

Updates the IIS web.config file with the current rules if it is writable.

  | 
| [make_site_theme_from_oldschool()](https://developer.wordpress.org/reference/functions/make_site_theme_from_oldschool/)`wp-admin/includes/upgrade.php` |

Creates a site theme from an existing theme.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_home_path/?output_format=md#changelog)󠁿

| Version | Description | 
| [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_home_path/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/get_home_path/?output_format=md#comment-content-623)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_home_path/#comment-623)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_home_path%2F%23comment-623)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_home_path%2F%23comment-623)
 4.  **Default Usage**
 5.      ```php
         // Return "Path: /var/www/htdocs/" or "Path: /var/www/htdocs/wordpress/" if it is subfolder.
         printf( 'Path: %s', get_home_path() );
         ```
     
 6.   * It’s also not available on the frontpage, it’s available only from wp-admin(
        backend). You should check if [is_admin()](https://developer.wordpress.org/reference/functions/is_admin/)
        otherwise you’ll get “Fatal error: Uncaught Error: Call to undefined function
        [get_home_path()](https://developer.wordpress.org/reference/functions/get_home_path/)”.
      * [dlawp](https://profiles.wordpress.org/dlawp/) [6 years ago](https://developer.wordpress.org/reference/functions/get_home_path/#comment-3813)
 7.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_home_path%2F%3Freplytocom%3D623%23feedback-editor-623)
 8.   [Skip to note 5 content](https://developer.wordpress.org/reference/functions/get_home_path/?output_format=md#comment-content-6456)
 9.    [Malcure Web Security](https://profiles.wordpress.org/malcure/)  [  3 years ago  ](https://developer.wordpress.org/reference/functions/get_home_path/#comment-6456)
 10. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_home_path%2F%23comment-6456)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_home_path%2F%23comment-6456)
 11. Apparently this doesn’t return the correct results when using WP_CLI.
 12.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_home_path%2F%3Freplytocom%3D6456%23feedback-editor-6456)
 13.  [Skip to note 6 content](https://developer.wordpress.org/reference/functions/get_home_path/?output_format=md#comment-content-6915)
 14.   [Rolf Allard van Hagen](https://profiles.wordpress.org/ravanh/)  [  2 years ago  ](https://developer.wordpress.org/reference/functions/get_home_path/#comment-6915)
 15. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_home_path%2F%23comment-6915)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_home_path%2F%23comment-6915)
 16. Note that `get_home_path()` is declared in wp-admin/includes/file.php which is
     not included by default, except on admin pages when wp-admin/includes/admin.php
     has been included.
 17.     ```php
         // Ensure get_home_path() is declared.
         require_once ABSPATH . 'wp-admin/includes/file.php';
     
         $home_path = get_home_path();
         ```
     
 18.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_home_path%2F%3Freplytocom%3D6915%23feedback-editor-6915)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_home_path%2F)
before being able to contribute a note or feedback.