PHP

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.

 Scroll to top