How can I include a file related to blog URL? Nothing seems to work

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?

Topic home-url bloginfo include php references Wordpress

Category Web


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';

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.