Bird
Raised Fist0
Wordpressframework~20 mins

Custom page templates in Wordpress - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Custom Page Template Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What does this WordPress custom page template output?

Consider this WordPress custom page template code snippet. What will be the visible output on the page when this template is assigned?

Wordpress
<?php
/* Template Name: Simple Greeting */
get_header();
?>
<h1>Hello, welcome to my site!</h1>
<?php get_footer(); ?>
AThe page shows a header, then the text 'Hello, welcome to my site!' in a large heading, then the footer.
BThe page shows only the text 'Hello, welcome to my site!' without header or footer.
CThe page shows the header and footer but no visible text content.
DThe page shows an error because the template name comment is missing.
Attempts:
2 left
💡 Hint

Remember that get_header() and get_footer() include the site's header and footer sections.

📝 Syntax
intermediate
2:00remaining
Identify the syntax error in this custom page template header

Which option correctly fixes the syntax error in this WordPress custom page template header comment?

Wordpress
<?php
/* Template Name: My Custom Page
get_header();
?>
A
&lt;?php
/* Template Name: My Custom Page */
get_header();
?&gt;
B
&lt;?php
// Template Name: My Custom Page
get_header();
?&gt;
C
&lt;?php
/* Template Name My Custom Page */
get_header();
?&gt;
D
&lt;?php
/* Template-Name: My Custom Page */
get_header();
?&gt;
Attempts:
2 left
💡 Hint

The template name comment must be properly closed with */.

❓ state_output
advanced
2:00remaining
What is the output of this custom page template with conditional content?

Given this WordPress custom page template code, what will be the output if the page has a custom field 'show_message' set to 'yes'?

Wordpress
<?php
/* Template Name: Conditional Message */
get_header();
if (get_post_meta(get_the_ID(), 'show_message', true) === 'yes') {
    echo '<p>Special message is shown!</p>';
} else {
    echo '<p>No special message.</p>';
}
get_footer();
?>
AThe page shows an error because get_post_meta is undefined.
BThe page shows the header, then '<p>No special message.</p>', then the footer.
CThe page shows only the footer with no message.
DThe page shows the header, then '<p>Special message is shown!</p>', then the footer.
Attempts:
2 left
💡 Hint

Check the condition that compares the custom field value to 'yes'.

🔧 Debug
advanced
2:00remaining
Why does this custom page template not display the assigned template content?

This custom page template is assigned to a page, but the page content does not appear. What is the most likely cause?

Wordpress
<?php
/* Template Name: Missing Content */
get_header();
// Missing the_content() function call
get_footer();
?>
AThe template file name must be page-missing-content.php to work.
BThe template does not call <code>the_content()</code>, so the page content is not displayed.
CThe template must use <code>wp_head()</code> to show content.
DThe template is missing <code>get_sidebar()</code>, so content is hidden.
Attempts:
2 left
💡 Hint

Think about how WordPress outputs the main page content inside templates.

🧠 Conceptual
expert
2:00remaining
How does WordPress determine which custom page template to use for a page?

Which statement best describes how WordPress selects a custom page template for a page?

AWordPress loads the first template file it finds in the theme folder regardless of page settings.
BWordPress always loads page.php unless a template file is named exactly after the page slug.
CWordPress checks the page's assigned template in the admin and loads the matching template file with the correct header comment.
DWordPress requires a plugin to enable custom page templates.
Attempts:
2 left
💡 Hint

Think about how WordPress admin lets you pick a template for a page.

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