How to: Include external PHP file in WordPress

So, you want to include (also include_once, require or require_once) another PHP file in one of your WordPress files?? Fine, but if your PHP file is in a different folder/directory to your WordPress installation you might run into problems.

After spending too long trawling the WordPress Codex trying to find a solution, I luckily found this post by Andy Fletcher – How to use a PHP include with WordPress

ABSPATH is your friend and the answer to your prayers. ? For example, assume your PHP files are in a folder off your web root called “thefolder”, you would include them using:

<?php include(ABSPATH . '/thefolder/thefile.php'); ?>

Simple when you know how.

5 thoughts on “How to: Include external PHP file in WordPress”

  1. You can include via your Themes Template folder too,

    Here’s an example:

    < ?php include( TEMPLATEPATH . '/includes/home-slider.php'); ?>

    TEMPLATEPATH = wp theme folder

  2. when ever I use the above function “” it comes out with an error “Parse error: syntax error, unexpected ‘/’ in /path/to/dir/wp/wp-content/themes/MYTheme/dir/test.php on line some where and when I check the file where I put the code above it shows “<?php include(ABSPATH . " nothing after it, pls help if you can.

  3. @Shahrukh…

    Did you copy/paste directly from here?

    It sounds like you’re missing the apostrophe – if you copied from here then you want to change it.

  4. That’s great! But what if one has a bunch of wordpress sites on the same server, and wants to include one file in all of the wordpress sites? ABSPATH only gets us up to the top level of the wordpress site.


    but if we have

    and want to include


    what then?

    A bridge include at the root of each WordPress site works.


    bridge.php says “include(‘/server/local/home/myaccount/cookies/cookiefile.php’)

    Now, everytime we update cookies/cookefile.php, all of, and get updated at once.

Leave a Reply

Your email address will not be published. Required fields are marked *