Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8078421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:47:17+00:00 2026-06-05T15:47:17+00:00

Is there a way to get the path to where WordPress is installed? I

  • 0

Is there a way to get the path to where WordPress is installed?

I was using the following:

$root = realpath($_SERVER["DOCUMENT_ROOT"]);

It is fine for http://www.example.com -> /usr/local/pem/vhosts/165312/webspace/httpdocs

It is not fine for http://www.example.com/blog since I need to hard code the folder name (blog).

Later I found a way by using this:

$iroot = getcwd();
$folder = explode("/", $iroot);
$dir = $folder[8]; // I know is 8
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
require "$root/$dir/wp-blog-header.php";

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?

Note: 1 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 require "wp-blog-header.php"; 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.

Note: 2 If instead of require "$root/$dir/wp-blog-header.php"; I use require "wp-blog-header.php"; 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:47:19+00:00Added an answer on June 5, 2026 at 3:47 pm

    Root example:

    • /usr/local/pem/vhosts/165312/webspace/httpdocs/blog-one
    • /usr/local/pem/vhosts/165312/webspace/httpdocs/blog-two
    • /usr/local/pem/vhosts/165312/webspace/httpdocs/some-blog

    The example below will work on any of the blogs (“blog-one”, “blog-two” and “some-blog”) and the script or file can be installed on any subfolder of the blog.

    $current_path = getcwd(); // Get the current path to where the file is located
    $folder = explode("/", $current_path); // Divide the path in parts (aka folders)
    $blog = $folder[8]; // The blog's folder is the number 8 on the path
    
    // $root = path without the blog installation folder.
    $root = realpath($_SERVER["DOCUMENT_ROOT"]);
    
    // Now I can require any WordPress file
    require "$root/$dir/wp-blog-header.php";
    
    // For the current installation
    // For example, wp-blog-header.php to get the blog name or
    // wp-config.php to access the database.
    

    This makes the script independent. The script will work on any folder on any WordPress installation installation as long as the folder is the number 8. If the installation is on a sub folder, the number 8 will have to be increased. Also bear in mind that the current path may have more or fewer folders, meaning that the script has to be adapted accordingly.

    Note: This will work by “hard coding” the folder position on the path and, as long as all installation have the same position, the script will work. The other way around is to hard code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to get Windows audio mixer levels using WMI? For example,
Is there any way to get a file name from a path? For example,
Using Javascript, is there a standard way to get the absolute path of an
Is there an easier way to get the path to an iOS application, than
Is there a nice way in the WinAPI to get a path relative to
Is there a way to get all versions of list item(s) using a CAML
Is there any way to get the path of documents currently open in Microsoft
Is there a way to programatically get the path to the databases/files an application
Is there a way to achieve the following? In my /www/var/public_html/index.php file i have
Is there a way to get the path to the movieClip I'm clicking? e.g.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.