Create a custom Wordpress template in few steps (Coding)

How to create custom Wordpress template?

Written By: Mohamed Atef

Published: 2021-06-26 | Comments: 0 | Category: Wordpress

Wordpress template

To create a Wordpress page template you need to have access to the theme directory & we prefer to use a Child theme to keep these edits just in case of theme updates then we need to add a specific comment at the top of the file & get the footer & header of the page

Step 1

Create a file to the template which you want to create  & the name of the file should be like this template-TEMPLATE-NAME.php

Step 2

You have to add the template name at the top of the file and the name should be included in PHP comment like the code below 

<?php/** * template name: Custom blog*/

After this step, you will be able to see the template name in the templates dropdown like the image below 

Step 3 

Add the header & footer in the template file using these functions get_header(); and get_footer(); 

Step 4 

Start writing the content inside the get_header & get_footer like 

<?php/** * template name: Custom blog*/ if ( ! defined( 'ABSPATH' ) ) { exit; } get_header();?><p >Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p><?php get_footer(); ?>

You might need to add div containers & wrappers this depend on your template you have to check the built in templates using the developer tools and do like them, or you need to copy the content of page.php into your template but you have to KEEP the COMMENT at the top of the template file because this is the key for Wordpress to recognize that this is a template & get the name of it 

That's all for today in the next posts I will try to show you how to get a custom loop inside your template, if you have any questions let me know in a comment below


There is no comments yet

Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

How to calculate estimate time of reading? Wordpress
Publish date: 2021-12-19 | Comments: 1

Tag: Wordpress

How to duplicate or clone Wordpress page ?
Publish date: 2021-04-08 | Comments: 0

Tag: Wordpress

One effective way to increase your WordPress website speed
Publish date: 2021-04-02 | Comments: 2

Tag: Wordpress

How to protect Wordpress login page?
Publish date: 2021-06-29 | Comments: 0

Tag: Wordpress

How to migrate Wordpress website from localhost to live site ?
Publish date: 2021-04-20 | Comments: 1

Tag: Wordpress