0
0
Wordpressframework~20 mins

Theme from scratch setup in Wordpress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
WordPress Theme Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What does this WordPress theme file output?

Given this index.php file in a new WordPress theme folder, what will the browser display when visiting the homepage?

Wordpress
<?php
// index.php
get_header();
?>
<h1>Welcome to my theme!</h1>
<?php
get_footer();
?>
AThe page shows the header content, then 'Welcome to my theme!' as a heading, then the footer content.
BThe page is blank because get_header() and get_footer() are undefined.
COnly 'Welcome to my theme!' is shown, no header or footer content.
DThe page shows an error because PHP tags are not closed properly.
Attempts:
2 left
💡 Hint

Think about what get_header() and get_footer() do in WordPress themes.

📝 Syntax
intermediate
2:00remaining
Which option correctly registers a new WordPress theme stylesheet?

Choose the correct code snippet to enqueue a stylesheet named style.css in a WordPress theme.

A
function theme_styles() {
  wp_enqueue_style('theme-style', 'style.css');
}
add_action('init', 'theme_styles');
B
function theme_styles() {
  wp_enqueue_script('theme-style', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts', 'theme_styles');
C
function theme_styles() {
  wp_register_style('theme-style', get_template_directory());
}
add_action('wp_enqueue_scripts', 'theme_styles');
D
function theme_styles() {
  wp_enqueue_style('theme-style', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts', 'theme_styles');
Attempts:
2 left
💡 Hint

Remember to use wp_enqueue_style and the right hook for loading stylesheets.

state_output
advanced
2:00remaining
What is the output of this WordPress loop in a theme file?

Consider this code inside a theme template file. What will it output if there are 3 posts?

Wordpress
<?php
if (have_posts()) :
  while (have_posts()) : the_post();
    the_title('<h2>', '</h2>');
  endwhile;
else :
  echo '<p>No posts found.</p>';
endif;
?>
AThe text 'No posts found.' because the loop is incorrect.
BA single &lt;h2&gt; with all post titles concatenated inside.
CThree post titles each wrapped in &lt;h2&gt; tags.
DAn error because the_post() is called outside the loop.
Attempts:
2 left
💡 Hint

Think about how the WordPress Loop works to display posts.

🔧 Debug
advanced
2:00remaining
Why does this WordPress theme not load the stylesheet?

Given this code in functions.php, why does the stylesheet not appear on the site?

Wordpress
function load_styles() {
  wp_enqueue_style('main-style', get_template_directory_uri() . '/style.css');
}
add_action('init', 'load_styles');
ABecause the hook 'init' is too early; styles should be enqueued on 'wp_enqueue_scripts'.
BBecause <code>get_template_directory_uri()</code> returns the wrong path; should use <code>get_stylesheet_directory_uri()</code>.
CBecause the style handle 'main-style' is reserved and cannot be used.
DBecause <code>wp_enqueue_style</code> requires a third argument for dependencies.
Attempts:
2 left
💡 Hint

Check the recommended hook for enqueuing styles in WordPress.

🧠 Conceptual
expert
3:00remaining
What is the purpose of the functions.php file in a WordPress theme from scratch?

Choose the best description of what functions.php does in a custom WordPress theme.

A<p>It is only used to define global variables accessible in templates.</p>
B<p>It acts like a plugin to add theme features, register menus, enqueue scripts/styles, and modify WordPress behavior.</p>
C<p>It automatically generates the theme's CSS styles based on PHP variables.</p>
D<p>It stores all the HTML markup for the theme's pages and templates.</p>
Attempts:
2 left
💡 Hint

Think about how WordPress themes add functionality beyond templates.