How to Add a PHP Page in WordPress

Do you want to create a custom PHP page in WordPress blog that will execute you PHP code in it, whilst remaining a part of the overall site CSS/theme/design? This article will show you how to add a PHP page in WordPress. Your custom PHP page template is like any other theme file in WordPress. You can add any HTML, template tags, or PHP code in this file. The easiest way to get started with your custom page is by copying the existing page template provided by your theme. The PHP code will make use of 3rd party APIs (so you need to include other PHP files).

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

Add a PHP Page in WordPress


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!). Enter the following at the top of the new file:

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

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.

Final Words

Your new page will use the php code defined in templatename.php. I hope you enjoyed this article if so, please share it with others.


Editorial Note: When you buy through links on our site, we may earn an affiliate commission. Commissions do not affect our writers' opinions or evaluations.