0
0
Wordpressframework~20 mins

Featured images in Wordpress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Featured Image Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this WordPress code snippet?
Consider this WordPress PHP code inside a theme template. What will it output if the current post has a featured image set?
Wordpress
<?php if (has_post_thumbnail()) {
  the_post_thumbnail('medium');
} else {
  echo 'No image available';
} ?>
ACauses a PHP syntax error
BDisplays the featured image in medium size
COutputs 'No image available' regardless of image
DDisplays the full content of the post
Attempts:
2 left
💡 Hint
Think about what has_post_thumbnail() checks and what the_post_thumbnail() does.
📝 Syntax
intermediate
2:00remaining
Which option correctly sets a featured image for a post programmatically?
You want to set a featured image for a post using PHP code. Which snippet correctly assigns an image with attachment ID 123 to post ID 45?
Aset_post_thumbnail(45, 123);
Bset_post_thumbnail(123, 45);
Cset_post_thumbnail(post_id=45, image_id=123);
Dset_post_thumbnail(45);
Attempts:
2 left
💡 Hint
Check the order of parameters in the function.
🔧 Debug
advanced
2:00remaining
Why does this code fail to display the featured image?
This code is inside the loop but does not show the featured image. What is the likely cause?
Wordpress
<?php the_post_thumbnail('thumbnail'); ?>
AThe image size 'thumbnail' is invalid
Bthe_post_thumbnail() must be called outside the loop
CThe post does not have a featured image set
DMissing echo before the_post_thumbnail()
Attempts:
2 left
💡 Hint
Check if the post actually has a featured image assigned.
🧠 Conceptual
advanced
2:00remaining
What is the purpose of 'add_theme_support' with 'post-thumbnails' in WordPress?
Why do themes call add_theme_support('post-thumbnails'); in their functions.php file?
ATo enable featured image support for posts and pages
BTo automatically add thumbnails to all images in posts
CTo register a new image size called 'post-thumbnails'
DTo disable featured images site-wide
Attempts:
2 left
💡 Hint
Think about what 'post-thumbnails' feature means in WordPress.
state_output
expert
2:00remaining
What is the output of this code when no featured image is set?
Given this code in a WordPress template, what will be the output if the current post has no featured image?
Wordpress
<?php
if (has_post_thumbnail()) {
  the_post_thumbnail('large');
} else {
  echo '<img src="/images/default.jpg" alt="Default image">';
}
?>
AThe featured image in large size
BNo output at all
CA broken image icon because the path is wrong
D<img src="/images/default.jpg" alt="Default image">
Attempts:
2 left
💡 Hint
Check the else block and what it echoes.