Challenge - 5 Problems
Featured Image Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2: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'; } ?>
Attempts:
2 left
💡 Hint
Think about what has_post_thumbnail() checks and what the_post_thumbnail() does.
✗ Incorrect
The function has_post_thumbnail() checks if the current post has a featured image. If yes, the_post_thumbnail('medium') outputs the image in medium size. Otherwise, it prints the fallback text.
📝 Syntax
intermediate2: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?
Attempts:
2 left
💡 Hint
Check the order of parameters in the function.
✗ Incorrect
The function set_post_thumbnail($post_id, $thumbnail_id) takes the post ID first, then the attachment ID of the image.
🔧 Debug
advanced2: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'); ?>Attempts:
2 left
💡 Hint
Check if the post actually has a featured image assigned.
✗ Incorrect
If the post has no featured image, the_post_thumbnail() outputs nothing. It does not cause an error.
🧠 Conceptual
advanced2: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?Attempts:
2 left
💡 Hint
Think about what 'post-thumbnails' feature means in WordPress.
✗ Incorrect
Calling add_theme_support('post-thumbnails'); enables the featured image option in the WordPress admin for posts and pages.
❓ state_output
expert2: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">'; } ?>
Attempts:
2 left
💡 Hint
Check the else block and what it echoes.
✗ Incorrect
If no featured image is set, the else block outputs an <img> tag with the default image path and alt text.