title: Get WordPress installation folder path
body: <p>Is there a way to get the path to where WordPress is installed?</p>
  
  <p>I was using the following:</p>
  
  <pre><code>$root = realpath($_SERVER["DOCUMENT_ROOT"]);
  </code></pre>
  
  <p>It is fine for www.example.com -> /usr/local/pem/vhosts/165312/webspace/httpdocs</p>
  
  <p>It is not fine for www.example.com/blog since I need to hard code the folder name (blog).</p>
  
  <p>Later I found a way by using this:</p>
  
  <pre><code>$iroot = getcwd();
  $folder = explode("/", $iroot);
  $dir = $folder[8]; // I know is 8
  $root = realpath($_SERVER["DOCUMENT_ROOT"]);
  require "$root/$dir/wp-blog-header.php";
  </code></pre>
  
  <p>But still it is a lot of complicated stuff. Is there a simple way to get where WordPress is installed (the path) without hard coding?</p>
  
  <p><strong>Note: 1</strong> WordPress functions will not work since this is somehow outside WordPress. As noted on the last example, the whole point of determine the WordPress installation path is to <code>require "wp-blog-header.php";</code> on multiple WordPress installations where each installation uses a different folder (example.com/blog-one and example.com/blog-two), not WordPress MU or multi site.</p>
  
  <p><strong>Note: 2</strong> If instead of <code>require "$root/$dir/wp-blog-header.php";</code> I use <code>require "wp-blog-header.php";</code> it will work as long as the file is in the same folder, but in my case the file will be sometimes in a different folder.</p>