I'm trying to add a require function in my functions.php, to include a file that is in the wp-content folder. I first tried this with the function content_url . 'filename.php'So the line of code looked like this: require(content_url . 'filename.php'. However this made the site crash, because of a die() probably. After that I tried to just use the direct link, so require('http://domainname.com/wp-content/filename.php'), but this also made the site to crash. Then I tried to use the add_template_part function, and for that I of course moved the filename.php file into the theme folder. Again this caused the site to crash. It looks like including is not allowed at all, since I can open the files in my browser. For testing purpose I changed the content of filename.php to echo "Form here";, and if I open this file in my browser directly, I indeed see Form here.

Could there possibly be anything I'm not seeing? Any suggestion is welcome!

1 Answer 1


Using an URL to include a php file will usually not work. You will need a filesystem path. Depending on where you .php file is located (in this case the template directory), you could use:

include( get_template_directory() . '/myfile.php' );


  • Ah I see, so why exactly can't I use content_url() then? Is there also a way to get the content directory? Thank you very much for this answer
    – Genie Kort
    Commented Jul 21, 2016 at 16:22
  • Try this link: codex.wordpress.org/Determining_Plugin_and_Content_Directories you would want the constant "WP_CONTENT_DIR". Try to echo your path to get them right. Commented Jul 21, 2016 at 16:24
  • content_url is an URL so the included file is not in your filesystem. For php to "reach" your code, it has to be included via the filesystem and not from a remote location like an URL. Hard to explain, sorry :D Commented Jul 21, 2016 at 16:25

Your Answer

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

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