WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I originally posted this on SO, but was directed this way.

I have a Wordpress installation in directory /blog.

I am trying to include multiple PHP files located in the root parent directory using relative paths such as "../../include/file.php".

Since Wordpress uses its install directory as the base, I tried to change it by including

<base href="http://mydomain.com" />

inside of the head, but it had no effect.

What can I do appropriately call these PHP files in my Wordpress theme?

share|improve this question
Can the non-WordPress PHP files be moved? What are they for? Could they instead be implemented in a WordPress-supported manner, such as custom page templates? – Chip Bennett Nov 25 '13 at 17:25
The PHP files belong to an existing web application that lives in the root directory. Wordpress is being installed in /blog to manage the blog content only, but we need to include many of the PHP files located in the root. – Tom Geoco Nov 25 '13 at 17:28
Then I'm not really sure how this question is WordPress-specific, and I don't know why SO sent you here to WPSE. Also: it appears that you got - and accepted - an answer at SO? – Chip Bennett Nov 25 '13 at 17:33
I did receive a solution that worked. At the time, all of the relative paths existed in the theme's index.php file. Since moving some of the paths to their respective footer and header files, the external PHP files were no longer being called. – Tom Geoco Nov 25 '13 at 17:40

In you case I'd edited my wp-config.php, and just after

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

I'd added

$path = explode( basename( dirname(__FILE__) ), ABSPATH ); 
define( 'MYSITEROOTPATH', $path[0] );

after that, everywhere I need, I'd used

// file.php is name of a file in root directory
include( MYSITEROOTPATH . 'file.php');
share|improve this answer
This looks promising. I'll give it a go, thank you. How can I define that variable globally so that I only have to include it where needed? In functions.php? Header.php? – Tom Geoco Nov 25 '13 at 17:34
I've updated the answer @TomGeoco – gmazzap Nov 25 '13 at 17:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.