You are probably here because you want to know how to create a custom page template in your WordPress website. You have landed in the right spot, as this small guide will detail the main steps and also benefits of creating your own custom page templates in your wordpress website. Read the whole story below:
What is a page template for wordpress ?
You are probably wondering what is a page template, and why would you need a page template in wordpress. Well, wordpress cms, comes with various templates for each type of custom post. By defauly, wordpress comes with a few standard post types, like single post (regular blog post) , page post (any page that you create), tags, and so much more. If you want to know all about the page templates in wordpress you can find more information in wordpress.org.
By default , in wordpress cms, the regular page template is located in page.php file, which is called “default”. But you can define your own page template by adding a new file inside your theme root folder. You can call it whatever you like, because wordpress will see this template based on the first comment line you will put in this file. See more information below how to create and what that file should contain
What is the benefit of custom templates ?
Why would you want to create a custom template ? Well, the idea is to control the header and footer and also content and other areas from your page. Or just have them missing completely, and use a page builder like elementor to build your header and footer manually, without sticking with the default get_header() call of wordpress.
How can I create a page template ?
Now we got to the core part, how can you create a page template in wordpress. You would need to get to your cpanel or hosting area, and go to the theme folder (the exact root folder of the theme you are using). Then create a new php file, with the name: mypage-template.php (in fact you can name it however you want, but keep it consistent). Next add the code below at the very beginning of the file.
<?php /** * Template Name: My Custom Template */ ?>
What to do next ?
Now that you have learned how to add a custom page template in your wordpress, you have to use it in a page. You need to go to Wp-admin > Pages > Add New and add a new page for your website. In the right hand side (unless you have your wordpress in a RTL mode, in that case is left hand side), you will see a dropdown from where you can choose your page template (if you are using Gutenberg and isnt disabled, then the screen will look a bit different). Now choose the page template you’ve just created.