Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve WordPress root directory path?

Tags:

wordpress

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

like image 579
Aadi Avatar asked Mar 01 '10 08:03

Aadi


People also ask

How do I find the root path in WordPress?

You can use get_site_url() function to get the base url of the wordpress site. Show activity on this post. First of all, this returns the path to the current template, and second, it returns the URI, not the filesystem path.

How do I find the root directory path?

In order to get the root directory path, you can use _DIR_ or dirname(). echo dirname(__FILE__); Both the above syntaxes will return the same result.


1 Answers

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.

like image 200
stefanglase Avatar answered Sep 24 '22 12:09

stefanglase