user

Mohamed Atef

26 Jun 2021

How to create custom Wordpress template?

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 style="margin: 30px;">
	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
Goodbye 

Comments

No Comments to show

© 2024 Copyrights reserved for web-brackets.com