How to add a custom page template in WordPress

Adding a custom page template in WordPress is relatively easy. It needs just a couple of minutes to create. Once created, the new custom page template can be chosen from admin panel, before or after adding a new page.

Admin Panel -> pages -> add new -> Choose template

The “Choose template” can be found on the right side of page content, under the page attributes section.

Adding custom page template

A WordPress custom page template is a PHP file created inside your theme folder. In this file you have to put the following code in top of the page in order to get recognized as a custom template from WordPress admin panel.

Choosing custom page template

After creating this php file, login in your admin panel, set the title of the page and choose the template we created from the dropdown menu at right of screen.

WordPress Template Section

The page is setup now. Click view page and your template will show up.

Adding content to the custom page template

Now you can decide if you want to receive data from WordPress or just create your custom code to receive data from another source.

If you want to receive content from WordPress page, just create a loop and style the template as you wish. Just don’t forget to include header and footer in your custom template. Here is an example:

If you want a custom page with codes not related to WordPress, without header and footer, delete everything from the custom page except the page template name that tells WordPress that this is a custom page.

Don’t forget to leave WordPress content empty in this case. Write your own custom code and when you access the page created from WordPress admin panel, your custom code will execute. Here is a example of a page that displays the sum of two numbers:

This page will display a page that prints the sum of two numbers. You can write whatever you want in here.

Hope this article helped you to understand WordPress custom pages.
If you liked this article, please share or tell a friend about this page.

Leave a reply