Reputation: 533
So, I have a custom php file in my wordpress root folder.
I have a link in frontend "example.com/custom.php"
that I would like to access.
How would I include this custom php in root folder in function.php so that it can be recognized by other wordpress function?
Thanks
Upvotes: 2
Views: 2620
Reputation:
Add this line in your themes functions.php:
include(ABSPATH . 'custom.php');
Explanation:
Your wp-config.php should contain the following code (near the bottom of the page):
/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
They are saving the path to the wordpress installation to ABSPATH.
It will be something like "/var/www/foo/" or similar. So you can concat the ABSPATH with path to your file. If for example, your php file is located inside some folder like this "example.com/somefolder/custom.php" you would use
include(ABSPATH . 'somefolder/custom.php');
Hope this helps!
Upvotes: 2