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.

When I was building my website locally using WAMP, I was just using simple

include '/extras/file.php';

Of course, that would start at the root folder, and look in the extras folder. However, now I'm putting the website on a webserver, and have put it in a subdomain (to not interfere with the current live site).

So I tried to change the include tags to a few different variations:

include (home_url().'/extras/file.php');
include home_url().'/extras/file.php'; - (without parent brackets)

And also the two variations above, but using bloginfo(url), get_bloginfo(url) etc but still nothing seems to actually output anything.

Could it possible be becuase of the subdomain? If I alter the include statement, I can sometimes echo the home url as text, but that's not what I want.

Am I doing it right? or is there something obviously wrong?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

The URL is the public web address. It is not related to the local file system. So what you need it a reference to the file system, not to the URL.

// path in relation to document root
include $_SERVER['DOCUMENT_ROOT'] . '/extras/file.php';

Or

// path in relation to current position
include dirname( __FILE__ ) . '/extras/file.php';
share|improve this answer
    
Thanks, that has worked (I used the first option). But my question is, when I move the site out of the subdomain and onto the main domain, will this need adjusting at all? –  Lee Collings Feb 12 at 11:56
    
Yes, it should. The question is where you need that include. There are specialized helper functions for plugins and themes for that. You should use these when ever possible. –  toscho Feb 12 at 11:58

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.