WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing a plugin that requires a large chunk of html. Now the way how it is set up now works.

return <<<EOT <html> EOT;

But I want to split the file into different php files that i can include. Now I tried this, but it does not work:

include(plugin_dir_url( __FILE__ ).'file.php');
return ob_get_clean();

Any know how this could be done?


Ok thanks Chris Carson to I have found the small error, I changed the code to:

include(plugin_dir_path( __FILE__ ).'/file.php');
return ob_get_clean();

This is working ok now, except for one small problem.

In the previous code I used something like this:

$variable = 'Hello!';

return <<<EOT

This would have made the following in html:


But now this:

$variable = 'Hello!';

include(plugin_dir_path( __FILE__ ).'/file.php');
return ob_get_clean();

This just prints


Any way to get the code working with variables.

share|improve this question
up vote 2 down vote accepted

When including files you don't want the URL, but the filesystem path instead. So...

include(dirname(__FILE__) . "/path/to/myfile.php");

Remember to put the first forward slash in /path/to/myfile.php, since dirname doesn't include the trailing slash.

share|improve this answer
AH! yeah of course. Been doing PHP way to long to make such a rookie mistake. Ok but is the ob_start(); method the best way to get the content, or does wordpress have a native function to do this. – Saif Bechan Aug 21 '11 at 15:18
I use ob_start, ob_get_clean -- I don't think there's a WP function for this. – Chris Carson Aug 21 '11 at 18:15

Your Answer


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.