Once a theme has been deployed, all the pages and posts of the website reflect its design. However, you might have come across websites that have pages with different design and appearances.

Unfortunately, themes do not provide the capability of different layouts for different pages. The only way out of this issue is to opt for a custom page template.

A custom page template could be used for a number of purposes. Some ideas include:

Show recent posts of each category.
Embed Google Map or any script.
List of all authors.
Recently uploaded images.
Custom design page for the portfolio.
Contact page.
The appearance of all the pages and posts that are created on a WordPress website is handled by a template file named page.php. Creating or editing a custom page template in WordPress requires basic knowledge of HTML, CSS, and PHP.

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

<?php /* Template Name: PageWithoutSidebar */ ?>

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

Now, we’re going to test our newly created template file.

Login to your hosting panel. Navigate to /wp-content/themes folder. Open your current theme folder and upload PageWithoutSidebar.php file there.

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

Create a new page and set its template to PageWithoutSidebar. Once done, Publish it.

Open the newly created page. As there are no design elements in the template yet, a blank page .

This shows that the custom page template in WordPress is successfully implemented.

It is now time to add a few lines of code to display the content of the page.

For this demo, I will discuss how you could customize the default Twenty Sixteen page template.

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

<?php get_header(); ?>

<div id="primary" class="content-area">
                <main id="main" class="site-main" role="main">
                                <?php
                                // Start the loop.
                                while ( have_posts() ) : the_post();

                                                // Include the page content template.
                                                get_template_part( 'template-parts/content', 'page' );

                                                // If comments are open or we have at least one comment, load up the comment template.
                                                if ( comments_open() || get_comments_number() ) {
                                                                comments_template();
                                                }

                                                // End of the loop.
                                endwhile;
                                ?>

                </main><!-- .site-main -->

                <?php get_sidebar( 'content-bottom' ); ?>

</div><!-- .content-area -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Paste this code into PageWithoutSidebar.php just below this line of code.


<?php /* Template Name: PageWithoutSidebar */ ?>

Save it!

Your complete PageWithoutSidebar.php file will look like below.

<?php /* Template Name: PageWithoutSidebar */ ?>

<?php get_header(); ?>

<div id="primary" class="content-area">

                <main id="main" class="site-main" role="main">

                                <?php

                                // Start the loop.
                                while ( have_posts() ) : the_post();

                                                // Include the page content template.
                                                get_template_part( 'template-parts/content', 'page' );

                                                // If comments are open or we have at least one comment, load up the comment template.
                                                if ( comments_open() || get_comments_number() ) {

                                                                comments_template();

                                                }

                                                // End of the loop.
                                endwhile;

                                ?>

                </main><!-- .site-main -->

                <?php get_sidebar( 'content-bottom' ); ?>

</div><!-- .content-area -->

<?php get_sidebar(); ?>

<?php get_footer(); ?>

Go back to your page and refresh it. You’ll observe everything is working in the way it does on the default WordPress Twenty Sixteen theme.

Subscribe To Our Newsletter

Subscribe To Our Newsletter

 

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!