Looking to add a new page template to your WordPress theme? You're in the right place. In this comprehensive guide, we'll walk you through the process step by step, ensuring you understand each step and can apply it to your own projects.

Before we dive in, let's ensure you have a basic understanding of WordPress themes and page templates. A WordPress theme is a collection of files that determine the design and functionality of your website. A page template, on the other hand, is a PHP file that defines how a specific type of page should be displayed. By the end of this guide, you'll be able to create and add a new page template to your WordPress theme.

Understanding Page Templates
WordPress comes with several default page templates, such as the default template, full-width template, and landing page template. However, you might want to create a custom template for a specific page, like an about page or a contact page. This is where creating a new page template comes in handy.

Page templates allow you to customize the layout, design, and functionality of a specific page. They are particularly useful when you want to break away from the standard layout of your theme. In the following sections, we'll show you how to create and add a new page template to your WordPress theme.
Creating a New Page Template

To create a new page template, you'll need to create a new PHP file in your theme's folder. Here's how to do it:
1. In your WordPress dashboard, navigate to Appearance > Theme File Editor. This will open the theme file editor, where you can edit your theme's files directly.
2. On the right-hand side, you'll see a list of your theme's files. Click on 'Theme Functions' (functions.php) to open it. This is where we'll add our new template.

Adding the Template to Your Theme
To add a new template to your theme, you'll need to add some code to your functions.php file. Here's what you need to do:
1. At the end of the functions.php file, add the following code:

```php function my_theme_register_page_templates( $theme ) { $theme->set( 'my-template', __( 'My Template', 'my-theme' ) ); } add_action( 'after_setup_theme', 'my_theme_register_page_templates' ); ```
Replace 'my-template' with the name you want for your template, and 'My Template' with the display name you want for it.
2. Save your changes. You should now see your new template listed in the Page Attributes section when editing a page in WordPress.




















Creating the Template File
Now that you've registered your new template, it's time to create the actual template file. Here's how:
1. In your theme's folder, create a new folder called 'templates'. This is where you'll store your custom templates.
2. Inside the 'templates' folder, create a new PHP file. Name it after your template, using the same name you used when registering the template (e.g., 'my-template.php').
Adding Content to Your Template
Now that you have your template file, it's time to add some content. Here's a basic structure to get you started:
```php
This is a basic template that displays the page title and content. You can customize it to include whatever content, layout, or functionality you need.
Using Your New Template
Now that you've created and added your new page template, it's time to use it. Here's how:
1. In your WordPress dashboard, navigate to Pages > Add New. This will open the page editor.
2. On the right-hand side, you'll see a section called Page Attributes. Here, you'll see a dropdown menu labeled Template. Select your new template from the list.
3. Click Publish to create your new page using your new template.
Congratulations! You've just created and added a new page template to your WordPress theme. This new template can be used to create pages with a custom layout, design, or functionality. The possibilities are endless. So, go ahead and experiment with your new template to create something truly unique.