Add a new page template wordpress
To add a new page template in WordPress, you can follow these steps:
Method 1: Using the WordPress Theme Editor
- Log in to your WordPress dashboard.
- Go to Appearance > Theme Editor.
- Click on the Templates tab.
- Click on the Add New button.
- Give your new template a name (e.g., "My New Page Template").
- Choose a template type (e.g., "Page").
- Click Create Template.
This will create a new PHP file in your theme's page-templates
directory. You can now edit this file to create your custom page template.
Method 2: Creating a new PHP file
- Log in to your WordPress dashboard.
- Go to File Manager (or use an FTP client like FileZilla).
- Navigate to your theme's directory (e.g.,
wp-content/themes/your-theme
). - Create a new folder called
page-templates
if it doesn't already exist. - Inside the
page-templates
folder, create a new PHP file with a name that starts withpage-
(e.g.,page-my-new-template.php
). - Open the file in a code editor and add your custom page template code.
Example Code
Here's an example of what your new page template file might look like:
<?php
/*
Template Name: My New Page Template
*/
?>
<!-- Your custom page template code goes here -->
<h1>Welcome to my new page template!</h1>
<p>This is a custom page template.</p>
Assigning the new page template to a page
- Go to Pages > All Pages.
- Click on the page you want to assign the new template to.
- Click on the Edit button.
- In the Page Attributes meta box, click on the Template dropdown menu.
- Select your new page template (e.g., "My New Page Template").
Your page should now use the new template.
Tips and Variations
- You can add custom fields to your page template using the
get_field()
function from the Advanced Custom Fields (ACF) plugin. - You can also use WordPress's built-in functions, such as
the_title()
andthe_content()
, to display page content. - To create a page template with a specific layout, you can use WordPress's
get_template_part()
function to include other template files. - You can also create page templates for specific page types, such as blog posts or archives, by using the
is_page()
function to check the page type.