Initially, most WordPress users use the platform, to create a simple website in just a few clicks. As soon as users start to learn about the full potential of the platform, they get more and more curious. Some users like to create their own Custom Post Types, Custom page templates and in some cases, users also end up developing their own WordPress theme. In this article, you will learn how to create and edit a custom page in WordPress.
What is a Custom Page Template
In WordPress, there are millions of themes available to customize and design the website according to your needs. There are websites which different designs for different pages. One limitation of WordPress themes is that it restricts users from altering layouts and functionality for different pages. This is where the page templates come into play.
In WordPress, page templates are an incredible method to include basic varieties or profoundly modified usefulness to your site. Many WordPress themes today come with several customization options such as, change the page’s full width, changing the sidebar’s location, and many more. All of these are done with the help of the template files. Customize page templates permit you to individualize any aspect of your WordPress site without influencing its remainder.
In WordPress by default,
page.php file is used by the WordPress theme to control the appearance of posts and pages. Also creating a custom page template requires a basic understanding of HTML, CSS, and PHP. We also recommend you to take the backup of your website since it involves making changes in your theme’s code.
Create a Custom Page in WordPress
Step 1: Create a template file.
Open any text editor and create a new file. Simply paste the following line of code at the top of the blank file:
<?php /* Template Name: CustomPageName */ ?>
The above line of code tells WordPress that this is page template and is ought to be perceived as CustomPageName. You can name your file whatever you want, as long as it ends with .php extension.
Once you have added the code to your file, save it on your computer.
Step 2: FTP File Transfer
In this step, you need to transfer your locally saved custom page template file in your web server. You can also directly upload the file in your webserver but using an FTP client is recommended.
Once connected, go to your current theme or child theme folder. You will find it in /wp-content/themes/ directory. Next, upload your custom page template file to your theme.
Note: During the testing phase we recommend you make changes to your child theme. On successful output, you can make a change in your Main theme file.
Step 3: Activating Custom Page Template
For this step, you need to log in to your WordPress Dashboard. Go to WordPress Pages >> Add New. You can also edit an existing page.
Now, on the page editing screen, scroll down to ‘Page Attributes’ section. The Page attributes section will consist of a drop-down menu. Select the custom template you just created.
Publish and open the newly created page. On opening, if you see a blank page that means your page template has been successfully implemented. The blank screen appears because the template does not consist of any design elements.
Step 4: Editing Custom Page Template
Once the custom page template is successfully implemented. Now it’s time to design your template. You can add any HTML, template tags, or PHP code in this file.
Open your FTP client and go to your Theme folder. From that folder download the page.php file. Open the page.php file using any text editor and copy all of its content except the header part.
The commented-out part in the top of the file is the header part. We do not copy the header part as our custom page template already has a header,
Paste the content below the following code line in custom page template file.
<?php /* Template Name: CustomPageName */ ?>
Save the file and upload it back to your theme folder in the server using FTP client.
Upon successful uploading, your custom page template will look exactly like all other pages. Now, you can make changes to your template in any way you want. For example, you can remove the sidebar, add custom PHP code, add any other HTML you want. If you want to remove the sidebar, just remove the following line of code from the bottom of the template.
<?php get_sidebar(); ?>
You can add the content either by editing the page in WordPress page editor screen or add custom content directly in your page template.
Note: The editing step can also be done online i.e. without downloading the page.php file locally.
We hope this article helps you clear your doubts. Please drop your queries in the comment section.
Also, if you want us to cover a specific topic, you can drop that into the comment section as well.