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?

  • 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? Commented Nov 25, 2013 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
    Commented Nov 25, 2013 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? Commented Nov 25, 2013 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
    Commented Nov 25, 2013 at 17:40

1 Answer 1


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');
  • 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
    Commented Nov 25, 2013 at 17:34
  • 1
    I've updated the answer @TomGeoco
    – gmazzap
    Commented Nov 25, 2013 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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