tags:

views:

234

answers:

4

How can retrieve root directory in wordpress...Please help.......

+1  A: 

Just echo this:

echo $_SERVER['DOCUMENT_ROOT'];
Sarfraz
+1  A: 

You can get blog url with get_bloginfo('url') However, dunno if you can get wp root. However, why do you need that?

Ionut Staicu
+1  A: 

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.

codescape
this is only useful if wp-config.php have already been included.in some cases (specifically an out of context ajax call to your plugin code) this does not hold true.
Omry
+1  A: 

I am guessing that you need to detect the wordpress root from your plugin or theme. I use the following code in FireStats to detect the root wordpress directory where firestats is installed a a wordpress plugin.

function fs_get_wp_config_path()
{
    $base = dirname(__FILE__);
    $path = false;

    if (@file_exists(dirname(dirname($base))."/wp-config.php"))
    {
        $path = dirname(dirname($base))."/wp-config.php";
    }
    else
    if (@file_exists(dirname(dirname(dirname($base)))."/wp-config.php"))
    {
        $path = dirname(dirname(dirname($base)))."/wp-config.php";
    }
    else
    $path = false;

    if ($path != false)
    {
        $path = str_replace("\\", "/", $path);
    }
    return $path;
}
Omry
this is what i looking for...thanks..
Ajith
cool. just remember to rename the function so we don't have function name collision if both plugins are installed :)
Omry