Custom php file in wordpress

Andrew Bartel is on the right path, but the link doesn’t quite do what you want.

For static PHP files to access WordPress core functionality you need to add this to the top of the PHP file:

define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );

(This code is from index.php in WordPress core)

Ideally though, you would want to create a WordPress Page Template in your theme or child theme with the custom PHP code.

Leave a Comment