Retrieve WordPress root directory path?

Aadi picture Aadi · Mar 1, 2010 · Viewed 165.7k times · Source

How can I retrieve the path to the root directory in WordPress CMS?

Answer

stefanglase picture stefanglase · Mar 1, 2010

Looking at the bottom of your wp-config.php file in the wordpress root directory will let you find something like this:

if ( !defined('ABSPATH') )
    define('ABSPATH', dirname(__FILE__) . '/');

For an example file have a look here:
http://core.trac.wordpress.org/browser/trunk/wp-config-sample.php

You can make use of this constant called ABSPATH in other places of your wordpress scripts and in most cases it should point to your wordpress root directory.