WordPress: WP theme on PHP page

Sometimes you might want to use your WordPress theme on pages that have a .php extension.

First you need to find your absolute path. Paste the following into a .php page, save it as absolutepath.php and upload to your server:

<?php echo $_SERVER['DOCUMENT_ROOT']; ?>

When you view the file, you can see your absolute path. After noting it, delete absolutepath.php for security reasons.

The following code is what will show your WordPress theme and will need to go at the beginning of the page. It will replace <?php include('header.php');?> or whatever code you have for your current header.

You need to change ABSOLUTEPATH/WORDPRESS to your absolute path and then, the folder where WordPress is installed. (You might not have it installed in a separate folder, in which case you would just put your absolute path.)

<?php require('/ABSOLUTEPATH/WORDPRESS/wp-blog-header.php');?>
<?php get_header(); ?>
<?php get_sidebar(); ?>

You may remove <?php get_sidebar(); ?> if you don’t have a sidebar or if it already included in your header file.

To include your footer, you would replace <?php include('footer.php');?> with the following:

<?php get_footer(); ?>

Save the file, upload, and your page should now be displaying your theme.