0
0
Wordpressframework~20 mins

Custom page templates in Wordpress - Practice Problems & Coding Challenges

Choose your learning style9 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.