How to add a PHP page to WordPress?

H

If you want to add a custom page with PHP for your WordPress blog, we have a very simply solutions. Follow the instructions below:

Duplicate page.php in your theme folder (/wp-content/themes/your_theme/).

Rename the new file as for example page-custom.php (where custom is what you want to call your new template).

To add your new page to the list of available templates in pages, enter the following at the top of the new file:

<?php
/*
Template Name: Custom Page
*/
?>

If you have this little code at the top of the new file, WordPress knows that this is a template and now you can modify this file as you want. Include other files, functions or whatever you need.

After that create a new page in your WordPress site. In the page editing screen you will see a Template dropdown in the Attributes widget to the right. Select your new template and publish the page. That is it!

Your new page will use your PHP code defined in page-custom.php

About the author

WP Fluent

We provide free tutorials & guides for you. 28% of the web uses WordPress.

Add comment

Recent Posts

Categories

Recent Comments

Archives

Tag Cloud