Do you want to know how to retrieve WordPress root directory path the correct way?

You will find many solutions for this question on internet but most of the solutions an extra effort and will decrease you website efficiency maybe by .00001 sec but why even waste that? WordPress has most of the thing built in to help you customise it the way you want.

If you have a look at the wp-config.php file and search for the code below, you will find that WordPress already have the root path assigned to a global variable.

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

Now if you you echo ABSPATH;, you will get root path echoed.

Feel free to comment below if you have some suggestions and queries.

Sahil Ahlawat

I am a Sr. Web Developer passionate about blogging and teaching. When I am not coding or writing blogs, I prefer traveling (Which I like most). I am also doing a bit or research on Indian Startups now a days.

Leave a Reply

Your email address will not be published. Required fields are marked *