Create a Custom Page Template in WordPress

Do you want to create a custom page in WordPress? You might notice that many WordPress sites have different layouts for different pages. A custom page allows you to have different layout in appearance from regular pages in WordPress. In this article, we will show you how to create a custom page in WordPress.

What is a Custom Page in WordPress

By default WordPress allows you to create posts and pages. Your WordPress theme controls the appearance of your pages by utilizing a template file called page.php.

This template file affects all single pages that you create in WordPress. However, not all pages are the same. Little changes in their layout and appearance can make them unique and a lot more useful.

Creating a custom page template in WordPress requires a basic understanding of HTML, CSS, and PHP.

Having said that, let’s jump into creating your first custom page in WordPress.

Creating a Custom Page in WordPress

First, you need to open a plain text editor like Notepad on your computer. In the blank file add this line of code at the top:

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

This code simply tells WordPress that this is a template file and it should be recognized as CustomPageT1. You can name your template anything you want as long as it makes sense to you.

Once you have added the code, save the file to your desktop as, custompaget1.php.

You can save the file with any name, just make sure that it ends with .php extension.

For this next step, you will need to connect to your website using an FTP client.

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.

Now you need to login to your WordPress admin area to create a new page or edit an existing one.

On the page editing screen, scroll down to ‘Page Attributes’ section, and you will find a template drop down menu. Clicking on it will allow you to select the template you just created.

Now if you change template and visit this page, then you will get to see a blank page. That’s because your template is empty and does not tell WordPress what to display.

Don’t worry, we will show you how to easily edit your custom page template.

Editing Your Custom Page Template

Your custom page template is like any other theme file in WordPress. You can add any HTML, template tags, or PHP code in this file.

The easiest way to get started with your custom page is by copying the existing page template provided by your theme.

Open your FTP client and go to your theme folder. There you will find a file called page.php. You need to download this file to your computer.

Open the page.php file in a plain text editor like Notepad, and copy all its content except the header part.

The header part is the commented out part at the top of the file. We are not copying it, because our custom page template already has one.

Now you need to open your custom page template file and paste it at the end.

Your custom page file would now look something like this:

<?php /* Template Name: CustomPageT1 */ ?>
<?php get_header(); ?>
<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
        // 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() ) {
            // End of the loop.
    </main><!-- .site-main -->
    <?php get_sidebar( 'content-bottom' ); ?>
</div><!-- .content-area -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Save your custom page template file and upload it back to your theme folder using FTP.

You can now visit the page you created using custom page template. It will now look exactly like your other pages in WordPress.

You can now continue editing your custom page template file. You can customize it in any way you want. For example, you can remove the sidebar, add custom PHP code, add any other HTML you want.

You can add the content by editing the page in WordPress page editor screen. You can also leave the content area in page editor completely empty, and add custom content directly in your page template.

Create a custom Header, Footer or Sidebar for Each WP Category

Have you ever seen WordPress blogs that have a separate header for different categories? We’ll share here a simple snippet that you can use to add custom header, footer, or even sidebar for each WordPress category.

To call a particular header, you will need to open your index.php and replace your normal header code with this one:

This code above is basically telling WordPress that if someone opens the category called “Blogging” then WordPress needs to display a file called header-blogging.php if it exist. If it does not exist, or if the category is not blogging, then WordPress displays the default header file.

To get a separate sidebar for each all you need to do is add the following code:

The code above will look for sidebar-blogging.php to replace the default footer file if the category is Blogging.

To get a separate footer for each category all you need to do is add the following code:

The code above will look for footer-blogging.php to replace the default footer file if the category is Blogging.

Install Google Analytics on your WordPress site

How to Install Google Analytics in WordPress

There are many different ways to setup Google Analytics in WordPress. We will show you three different methods where the first option is the easiest and the last being the hardest.

You can choose the one that best suits your needs.

1. Google Analytics for WordPress by MonsterInsights

MonsterInsights is the most popular Google Analytics plugin for WordPress. Over 1 million websites use it including the likes of Bloomberg, PlayStation, Zillow, and more.

It is the easiest and by far the best way to add Google Analytics to WordPress (for all users beginners and experts).

MonsterInsights has both a free version and the Pro version. In this tutorial, we will be using the MonsterInsights free version.

You can use the MonsterInsights Pro version if you want more advanced features like Ecommerce tracking, Ads tracking, Author tracking, etc. The process of setting them up is the same.

Let’s get started.

The first thing you need to do is install and activate the MonsterInsights plugin.

For more details, and if you want to learn how to install and manage WordPress plugins, see our WordPress basics course.

Upon activation the plugin will add a new menu item labeled ‘Insights’ to your WordPress admin menu. You need to visit Insights » Settings to configure the plugin settings.

On this screen, you need to click on ‘Authenticate with your Google account’ button to connect Google Analytics with your WordPress site.

authenticate WP

This will bring up a popup where you will be able to authenticate with your Google Account.

authenticate Google

Click on ‘Next’ to continue.

Now you need to click on ‘Click to get Google code’ button.

Get authentication code

This will bring up another popup with the message ‘MonsterInsights would like access to your Google Analytics data’.

Click on the ‘Allow’ button to continue.


The authentication popup will now show you a line of code which you need to copy.

authentication code

Next, you need to enter this code in the MonsterInsights popup and then click on ‘Next’ to continue.

enter google code

The final step is to select the profile you want to track. You need to select your website here and then click on the next button to continue.

select google pofile

That’s all you have successfully installed and setup Google Analytics on your WordPress site.

Remember, it will take Google Analytics sometime before showing your stats.

The best part about MonsterInsights is that you can view your Google Analytics report inside your WordPress dashboard. Simply visit Insights » Reports page to checkout a quick overview of your analytics data.


You can go also go in the Tracking tab to customize the tracking settings based on your needs:

insights tracking

Note: MonsterInsights was formerly known as Google Analytics for WordPress by Yoast.

2. Insert Headers and Footers Plugin

This method is not as not as good as MonsterInsights because you will not be able to do advanced tracking configuration, and you will not be able to view Google Analytics data in your WordPress dashboard.

First, you need to install and activate the Insert Headers and Footers plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit Settings » Insert Headers and Footers page. Here you need to paste the Google Analytics code that you copied in step 4 into the headers section.

adding code to header footer in wrdpress
Don’t forget to click on the save changes button to store your settings.

3. Install Google Analytics in WordPress Theme

This method is for advanced users only who are familiar with code. It is somewhat unreliable because your code will disappear if you switch or update the theme. We almost never recommend using this method.

If this is your first time adding code to your WordPress files, then you should check out our guide on how to copy paste code snippets in WordPress.

Add code in header.php file

Simply edit the header.php file in your WordPress theme and paste the code you copied in step 4 right after the <body> tag.

Don’t forget to save your changes and upload the file back to your server.

Add via Functions File

You can also add Google Analytics tracking code to WordPress functions file. It will then automatically add code to every page on your WordPress site.

You will need to add this code to your theme’s functions.php file.

1 <?php
2 add_action('wp_head', 'wpb_add_googleanalytics');
3 function wpb_add_googleanalytics() { ?>
5 // Paste your Google Analytics code from Step 4 here
7 <?php } ?>

Viewing Reports on Google Analytics Website

Google Analytics is capable of showing you a treasure of data collected from your stats. You can view this data by visiting your Google Analytics dashboard and clicking on the reporting tab.

Google Analytics reports

You will see the built-in Google Analytics reports in the left column. Each section is divided into different tabs and clicking on a tab will expand it to show more options.

  • Audience tab will show reports to help you understand your users.
  • Acquisition reports explore where your users came from.
  • Behavior reports summarize what your users do after they arrive on your site.
  • Conversion reports show how well you’re doing against your goals.

We hope this article helped you learn how to install Google Analytics in WordPress.