Bird
Raised Fist0
Wordpressframework~20 mins

Image optimization in Wordpress - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
WordPress Image Optimization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding WordPress Image Sizes
In WordPress, what is the purpose of the add_image_size() function?
AIt registers a new custom image size to be generated when images are uploaded.
BIt compresses existing images in the media library to reduce file size.
CIt deletes unused images from the media library to save space.
DIt converts images to WebP format automatically on upload.
Attempts:
2 left
💡 Hint
Think about how WordPress creates different image versions for different uses.
❓ component_behavior
intermediate
2:00remaining
Behavior of Lazy Loading in WordPress
What happens when you enable native lazy loading for images in WordPress?
AImages are converted to SVG format for faster rendering.
BAll images load immediately but at a lower resolution to save bandwidth.
CImages load only when they are about to enter the browser viewport, improving page speed.
DImages are preloaded before the page content to avoid delays.
Attempts:
2 left
💡 Hint
Lazy loading delays image loading until needed.
📝 Syntax
advanced
2:00remaining
Correct Syntax for WebP Support in WordPress
Which code snippet correctly enables WebP image support in WordPress by adding WebP to allowed mime types?
Aadd_filter('mime_types', function($mimes) { $mimes['webp'] = 'image/webp'; return $mimes; });
Badd_filter('mime_types', function($mimes) { $mimes['webp'] = 'image/jpeg'; return $mimes; });
Cadd_action('mime_types', function($mimes) { $mimes['webp'] = 'image/webp'; });
Dadd_filter('upload_mimes', function($mimes) { $mimes['webp'] = 'image/png'; return $mimes; });
Attempts:
2 left
💡 Hint
Check the correct hook and mime type for WebP.
🔧 Debug
advanced
2:00remaining
Debugging Image Compression Plugin Conflict
A WordPress site uses two image compression plugins. After activating both, images are not compressed properly. What is the most likely cause?
AThe server does not have enough storage space for compressed images.
BWordPress does not support image compression plugins.
CThe images are already compressed and cannot be compressed further.
DThe plugins conflict because both try to compress images on upload, causing errors.
Attempts:
2 left
💡 Hint
Think about how plugins might interfere with each other.
❓ state_output
expert
3:00remaining
Result of Custom Image Size Usage in Theme
Given this code in a WordPress theme's functions.php:
add_image_size('custom-thumb', 300, 200, true);
the_post_thumbnail('custom-thumb');

What will be the output behavior when displaying the post thumbnail?
Wordpress
add_image_size('custom-thumb', 300, 200, true);
the_post_thumbnail('custom-thumb');
AThe post thumbnail is displayed at original size ignoring the custom size.
BThe post thumbnail is displayed cropped to exactly 300x200 pixels.
CThe post thumbnail is displayed stretched to 300x200 without cropping.
DThe_post_thumbnail function throws an error because 'custom-thumb' is not a default size.
Attempts:
2 left
💡 Hint
Check the meaning of the last parameter in add_image_size.

Practice

(1/5)
1. What is the main benefit of image optimization in WordPress websites?
easy
A. It makes the website load faster by reducing image file sizes.
B. It increases the image resolution for better quality.
C. It adds watermarks to images automatically.
D. It changes image colors to grayscale.

Solution

  1. Step 1: Understand image optimization purpose

    Image optimization reduces file sizes to improve loading speed.
  2. Step 2: Compare options

    Only It makes the website load faster by reducing image file sizes. mentions faster loading by reducing file size, which is correct.
  3. Final Answer:

    It makes the website load faster by reducing image file sizes. -> Option A
  4. Quick Check:

    Image optimization = faster loading [OK]
Hint: Think about website speed and image file size relation [OK]
Common Mistakes:
  • Confusing optimization with increasing image quality
  • Thinking optimization changes image colors
  • Assuming optimization adds watermarks
2. Which WordPress function is used to resize images for optimization?
easy
A. wp_get_image_editor()
B. wp_enqueue_script()
C. get_post_meta()
D. add_theme_support()

Solution

  1. Step 1: Identify image resizing function

    wp_get_image_editor() provides tools to resize and edit images.
  2. Step 2: Eliminate unrelated functions

    Other options relate to scripts, metadata, or theme features, not image resizing.
  3. Final Answer:

    wp_get_image_editor() -> Option A
  4. Quick Check:

    Image resizing = wp_get_image_editor() [OK]
Hint: Look for functions with 'image' and 'editor' in the name [OK]
Common Mistakes:
  • Choosing functions unrelated to images
  • Confusing script or theme functions with image functions
  • Not knowing WordPress image API
3. What will this WordPress code snippet do?
add_filter('wp_generate_attachment_metadata', function($metadata) {
  $metadata['sizes']['thumbnail']['width'] = 150;
  return $metadata;
});
medium
A. Prevent images from being uploaded.
B. Change the thumbnail image width to 150 pixels during upload.
C. Add a new image size called 'thumbnail' with width 150.
D. Delete all image thumbnails from the media library.

Solution

  1. Step 1: Understand the filter used

    'wp_generate_attachment_metadata' modifies image metadata after upload.
  2. Step 2: Analyze code effect

    The code sets the 'thumbnail' size width to 150 pixels in metadata, changing thumbnail size.
  3. Final Answer:

    Change the thumbnail image width to 150 pixels during upload. -> Option B
  4. Quick Check:

    Filter modifies thumbnail width = 150 [OK]
Hint: Filters modify data; here it changes thumbnail width [OK]
Common Mistakes:
  • Thinking it deletes thumbnails
  • Assuming it adds new image sizes
  • Believing it blocks uploads
4. You added this code to optimize images but thumbnails are not resizing:
add_filter('wp_generate_attachment_metadata', function($metadata) {
  $metadata['sizes']['thumbnail']['width'] = 150;
  return $metadata;
});

What is the likely problem?
medium
A. You must use 'wp_enqueue_scripts' instead of this filter.
B. The filter name is incorrect and never runs.
C. The code changes metadata but does not regenerate thumbnails.
D. Thumbnails cannot be resized in WordPress.

Solution

  1. Step 1: Understand what the code does

    The code changes metadata but does not recreate image files.
  2. Step 2: Identify missing step

    Thumbnails must be regenerated to apply new sizes; metadata alone is not enough.
  3. Final Answer:

    The code changes metadata but does not regenerate thumbnails. -> Option C
  4. Quick Check:

    Metadata change ≠ thumbnail regeneration [OK]
Hint: Changing metadata needs regeneration to update images [OK]
Common Mistakes:
  • Assuming filter runs incorrectly
  • Confusing script enqueue with image filters
  • Believing thumbnails cannot be resized
5. You want to serve WebP images in WordPress for better performance but keep JPEG fallback. Which approach is best?
hard
A. Convert images to PNG format for better compression.
B. Rename all JPEG files to .webp manually and upload them.
C. Disable JPEG uploads and only allow WebP images.
D. Use a plugin that generates WebP versions and serves them with fallback support.

Solution

  1. Step 1: Understand WebP and fallback needs

    WebP is modern and efficient but not supported by all browsers, so fallback is needed.
  2. Step 2: Evaluate options

    Only Use a plugin that generates WebP versions and serves them with fallback support. uses a plugin to generate WebP and fallback automatically, which is best practice.
  3. Final Answer:

    Use a plugin that generates WebP versions and serves them with fallback support. -> Option D
  4. Quick Check:

    WebP + fallback = plugin solution [OK]
Hint: Use plugins for WebP with fallback, not manual renaming [OK]
Common Mistakes:
  • Manually renaming files breaks compatibility
  • Disabling JPEGs removes fallback
  • Using PNG instead of WebP for compression
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard