How to add Custom PHP page to WordPress?

If you want to create a custom page for my WordPress blog that will execute my PHP code in it, whilst remaining a part of the overall site CSS/theme/design.

The PHP code will make use of 3rd party APIs (so I need to include other PHP files)

How do I accomplish this?

N.B. I do not have a specific need to interact with the WordPress API – apart from including certain other PHP libs I need I have no other dependencies in the PHP code I want to include in a WP page. So obviously any solution that didn’t require learning the WP API would be the best one.

You don’t need to interact with the API or use a plugin.

First, duplicate post.php or page.php in your theme folder (under /wp-content/themes/themename/).

Rename the new file as templatename.php (where templatename is what you want to call your new template). To add your new template to the list of available templates, enter the following at the top of the new file:

<?php
/*
Template Name: Name of Template
*/?>

You can modify this file (using PHP) to include other files or whatever you need.

Then create a new page in your WordPress blog, and in the page editing screen you’ll see a Template dropdown in the Attributes widget to the right. Select your new template and publish the page.

Your new page will use the PHP code defined in templatename.php

Written By:

Sarmad Gardezi A blog scientist by Mind and a Passionate Blogger by heart. Sarmad is Freelancer, Entrepreneur and Google Apps Scripts Developer from Islamabad, Pakistan.

Subscribe to Email Newsletter