Bird
Raised Fist0
Wordpressframework~10 mins

Custom page templates in Wordpress - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Custom page templates
Create PHP file in theme folder
↓
Add template header comment
↓
Write custom HTML/PHP code
↓
Save file
↓
Go to WordPress Admin
↓
Create/Edit page
↓
Select custom template from dropdown
↓
Publish/Update page
↓
Page uses custom template for display
This flow shows how WordPress reads a custom page template file and applies it when you select it for a page in the admin.
Execution Sample
Wordpress
<?php
/*
Template Name: My Custom Template
*/
get_header();
echo '<h1>Welcome!</h1>';
get_footer();
This code defines a custom page template that shows a header, a welcome message, and a footer.
Execution Table
StepActionEvaluationResult
1Create PHP file with template headerFile named my-custom-template.php with Template Name commentWordPress recognizes it as a template
2Write custom HTML/PHP codeAdd get_header(), content, get_footer()Template outputs custom page structure
3Save file in active theme folderFile is accessible by WordPressTemplate appears in page editor dropdown
4Open WordPress Admin > Pages > Add NewCreate new pagePage editor loads
5Select 'My Custom Template' from Template dropdownTemplate assigned to pagePage will use custom template on display
6Publish pagePage saved with templatePage URL shows custom template output
7Visit page URLWordPress loads template filePage shows header, 'Welcome!' message, footer
8ExitNo more stepsProcess complete
💡 All steps done, custom template applied to page display
Variable Tracker
VariableStartAfter Step 1After Step 3After Step 5After Step 7Final
Template FileNonemy-custom-template.php createdFile saved in theme folderSelected in page editorLoaded by WordPressUsed to render page
Page Template SettingDefaultDefaultDefaultMy Custom TemplateMy Custom TemplateMy Custom Template
Page OutputDefault theme outputDefaultDefaultDefaultCustom template outputCustom template output
Key Moments - 3 Insights
Why doesn't my custom template appear in the page editor dropdown?
Make sure the PHP file has the correct 'Template Name' comment at the top and is saved in the active theme folder, as shown in execution_table step 3.
What happens if I forget to call get_header() or get_footer() in my template?
Your page will miss the header or footer sections, so the page layout may look broken. See execution_table step 2 where these functions are included.
Can I use a custom template for posts or only pages?
Custom page templates apply only to pages, not posts. For posts, you need to create custom single post templates or use other methods.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does WordPress recognize the file as a template?
AStep 6
BStep 4
CStep 1
DStep 7
💡 Hint
Check the 'Evaluation' column in step 1 about the Template Name comment.
According to variable_tracker, what is the 'Page Template Setting' after selecting the template in the editor?
ADefault
BMy Custom Template
CNone
DHeader/Footer
💡 Hint
Look at the 'After Step 5' column for 'Page Template Setting'.
If you forget to save the PHP file in the theme folder, what will happen in the execution flow?
ATemplate does not appear in dropdown
BTemplate appears in dropdown but page shows error
CPage uses default template automatically
DWordPress crashes
💡 Hint
Refer to execution_table step 3 about saving the file and template availability.
Concept Snapshot
Custom page templates in WordPress:
- Create a PHP file in your theme folder
- Add a comment: /* Template Name: Your Template */
- Write your custom HTML/PHP code
- Save the file
- In WordPress admin, select this template for a page
- Publish page to see custom layout
- Templates only apply to pages, not posts
Full Transcript
Custom page templates in WordPress let you design unique layouts for specific pages. You start by creating a PHP file in your active theme folder. At the top of this file, you add a special comment with the template name. Then you write your custom code, usually including calls to get_header() and get_footer() for consistent site design. After saving the file, WordPress detects it and shows it in the page editor under the template dropdown. When you select this template for a page and publish it, WordPress uses your custom template to display that page. This process only works for pages, not posts. Remember to save the file in the correct theme folder and include the template name comment, or WordPress won't recognize your template.

Practice

(1/5)
1. What is the main purpose of a custom page template in WordPress?
easy
A. To create a unique layout for a specific page
B. To change the WordPress admin dashboard style
C. To add new plugins automatically
D. To backup the website content

Solution

  1. Step 1: Understand what a page template does

    A custom page template allows you to design a different layout or look for a specific page.
  2. Step 2: Compare options to the purpose

    Only To create a unique layout for a specific page describes creating a unique layout for a page, which matches the purpose of custom page templates.
  3. Final Answer:

    To create a unique layout for a specific page -> Option A
  4. Quick Check:

    Custom page template = unique page layout [OK]
Hint: Custom templates change page look, not admin or backups [OK]
Common Mistakes:
  • Confusing templates with plugins
  • Thinking templates change admin dashboard
  • Believing templates backup content
2. Which of the following is the correct way to start a custom page template file in WordPress?
easy
A.
B.
C.
D.

Solution

  1. Step 1: Recall the required comment format

    WordPress requires a PHP comment with "Template Name:" inside the file to recognize a custom page template.
  2. Step 2: Identify the correct syntax

    uses the correct PHP comment format: .
  3. Final Answer:

    -> Option C
  4. Quick Check:

    Template comment must be PHP block comment with 'Template Name:' [OK]
Hint: Use PHP block comment with 'Template Name:' exactly [OK]
Common Mistakes:
  • Using HTML comments instead of PHP comments
  • Writing 'Page Template' instead of 'Template Name'
  • Using single-line comments that WordPress ignores
3. Given this custom page template header:
<?php
/* Template Name: Special Layout */
?>

What happens when you assign this template to a page in WordPress?
medium
A. The page uses the default theme layout
B. The page uses the 'Special Layout' template for its design
C. The page becomes inaccessible
D. The template is ignored and a 404 error shows

Solution

  1. Step 1: Understand template assignment

    Assigning a custom template to a page tells WordPress to use that template's layout for rendering the page.
  2. Step 2: Match template name to page behavior

    The template named 'Special Layout' will be used to display the page, overriding the default layout.
  3. Final Answer:

    The page uses the 'Special Layout' template for its design -> Option B
  4. Quick Check:

    Assign template = page uses that layout [OK]
Hint: Assigning template changes page layout, not error or default [OK]
Common Mistakes:
  • Thinking template assignment causes errors
  • Assuming default layout stays after assignment
  • Confusing template name with page title
4. You created a custom page template file named custom-template.php with the correct header comment, but it does not appear in the WordPress page editor template dropdown. What is the likely cause?
medium
A. The page editor does not support templates
B. The template name comment is missing
C. The file has a syntax error in PHP code
D. The file is not in the active theme folder

Solution

  1. Step 1: Check template file location

    WordPress only detects custom templates inside the active theme's root folder or its subfolders.
  2. Step 2: Eliminate other causes

    The question states the header comment is correct, so B is unlikely. Syntax errors might cause errors but usually still show the template. The page editor supports templates by default.
  3. Final Answer:

    The file is not in the active theme folder -> Option D
  4. Quick Check:

    Template file must be inside active theme folder [OK]
Hint: Place template file inside active theme folder to appear [OK]
Common Mistakes:
  • Placing template in plugin folder instead of theme
  • Forgetting to refresh page editor after adding template
  • Assuming page editor lacks template support
5. You want to create two different custom page templates: one for a full-width layout and one with a sidebar. How should you organize your files and comments to make both templates available and selectable in WordPress?
hard
A. Create two PHP files in the theme folder, each with a unique 'Template Name' comment
B. Create one PHP file with two 'Template Name' comments inside
C. Create two PHP files but only one needs the 'Template Name' comment
D. Create two PHP files in a plugin folder with 'Template Name' comments

Solution

  1. Step 1: Understand template file requirements

    Each custom page template must be a separate PHP file with its own unique 'Template Name' comment.
  2. Step 2: Confirm file location and comments

    Both files must be inside the active theme folder. Plugins do not register page templates this way by default.
  3. Final Answer:

    Create two PHP files in the theme folder, each with a unique 'Template Name' comment -> Option A
  4. Quick Check:

    Separate files + unique names = multiple templates [OK]
Hint: One template per file with unique name inside theme folder [OK]
Common Mistakes:
  • Putting multiple template names in one file
  • Placing templates outside the theme folder
  • Assuming plugins auto-register page templates
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard