Uncategorized

How to Create a Custom Page Template in a WordPress Theme

One of the key selling points of WordPress is the idea of ​​themes. A single theme adds great value to the design and functionality of the website. However, there are websites that have different themes on different pages.

Unfortunately, multiple WordPress themes prevent users from changing layouts and functionality for any other page in the hierarchy. The WordPress custom page template allows users to incorporate custom requirements like the right/left sidebar on a specific page, an additional call-to-action feature, or maybe a unique header for a specific landing page. Let’s dive further to see how a WordPress custom page template displays different types of content.

Reading: How to create a website with wordpress template

A WordPress custom page template can be used for a number of purposes. Some ideas are:

  • Show latest posts of each category
  • Embed google map or any script
  • List of all authors.
  • Recently Uploaded Images
  • Custom Portfolio Theme Page
  • Contact Us Page

The look and feel of all pages and posts created on a WordPress website is managed by a template file called page.php. Creating or editing a custom page template in WordPress requires basic knowledge of HTML, CSS and PHP.

Just open any text editor and paste the following code in it.

The line of code above tells WordPress that this is a template file called PageWithoutSidebar. You can use any name. Now save this file as PageWithoutSidebar.php. Again, you can use any other name for the file. But don’t forget the extension .php

See also  How Much Does It Cost to Build a Website For a Small Business?

Now let’s test our newly created template file.

Log in to your PHP hosting or another hosting panel. In this example, I am using Cloudways WordPress hosting. Cloudways supports WordPress applications with AWS, DigitalOcean, GCP, Linode, and Vultr provider options. Navigate to the /wp-content/themes folder. Open your current theme folder and upload the PageWithoutSidebar.php file there.

Go to WordPress Admin Panel > Pages > Add New. You can see the new custom page template on the right.

Add New Page

Create a new page and set its template to PageWithoutSidebar. When you’re done, publish it.

See also: How to Set the Logo of Your Website in Thrive Theme Builder

Page without sidebar

Open the newly created page. Since the template doesn’t have any design elements yet, you’ll see a blank page as in the image below.

Blank Page

This shows that the custom page template has been implemented successfully in WordPress, so you can enter a create custom responsive WordPress theme

Now it’s time to add a few lines of code to display the content of the page.

For this demo, I’ll explain how to do this could Customize the default Twenty Sixteen page template.

The default appearance of the pages is generated by the page.php file, located in /wp-contents /themes/YOUR THEME/ is located. Folder. Open page.php and copy this code.

In PageWithoutSidebar.php, paste this code just below this line of code.

Save!

Your complete PageWithoutSidebar.php file will look like this.

Go back to your page and refresh it. You will see that everything works as it does on the default WordPress Twenty Sixteen theme.

See also  How to Create a Wireframe in Photoshop

See also: How to animate a logo in 7 steps

WordPress Default Theme

Now we can customize it. As you can see, there is a sidebar on the right side. I will remove the sidebar from this page only. All other pages have the default appearance of the Twenty Sixteen theme.

Open the PageWithoutSidebar.php file. Scroll down to the bottom of the file and remove:

This is the line of code that brings the sidebar onto the page. After removing the line, save it. Open the URL of the page and the sidebar is gone!

Sidebar removed

As you can see, the sidebar has been successfully removed from this page. However, the text alignment is not good. On the right is a space. The solution is to align and expand the text to fill the screen.

Go back to PageWithoutSidebar.php and find:

Just change “content-area” to “site-content-fullwidth” and you’re done. Refresh the page and the content is full width.

Wide Content Area

Still curious as to why I created a custom page template when I could just edit the page.php file can? It is quite obvious that when the page.php file is edited, all pages of the website would reflect the changes. To apply a custom look and feel to specific pages, the custom page template in WordPress comes in handy. You can also define a custom user role in WordPress to assign different permissions to users.

If you have any questions, please feel free to ask them by posting them in the comments section below.

See also: Easily Create and Edit a Google Sheet Drop Down List in 2023

See also  How to create a YouTube channel for your brand in 5 steps

.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button