Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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
1  
I've updated the answer @TomGeoco –  G. M. Nov 25 '13 at 17:41
add comment

Your Answer

 
discard

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.