0

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?

1 Answer 1

0

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';
2
  • 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
    Feb 12, 2014 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.
    – fuxia
    Feb 12, 2014 at 11:58

Your Answer

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

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