Bird
0
0

You want to display a featured image with a custom CSS class and alt text. Which code snippet correctly does this?

hard📝 Application Q8 of 15
Wordpress - Content Management
You want to display a featured image with a custom CSS class and alt text. Which code snippet correctly does this?
Athe_post_thumbnail('large', [class => 'custom-img', 'alt' => 'Post image']);
Bthe_post_thumbnail('large', 'class=custom-img alt=Post image');
Cthe_post_thumbnail('large', 'custom-img', 'Post image');
Dthe_post_thumbnail('large', array('class' => 'custom-img', 'alt' => 'Post image'));
Step-by-Step Solution
Solution:
  1. Step 1: Understand the_post_thumbnail() second parameter

    The second parameter accepts an array of attributes like class and alt.
  2. Step 2: Use correct PHP array syntax

    Use array('class' => 'custom-img', 'alt' => 'Post image') for attributes.
  3. Final Answer:

    the_post_thumbnail('large', array('class' => 'custom-img', 'alt' => 'Post image')); -> Option D
  4. Quick Check:

    Attributes passed as array = the_post_thumbnail('large', array('class' => 'custom-img', 'alt' => 'Post image')); [OK]
Quick Trick: Pass attributes as array in second argument of the_post_thumbnail() [OK]
Common Mistakes:
  • Using short array syntax with => but wrong brackets
  • Passing attributes as string instead of array
  • Using multiple string arguments instead of one array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes