Bird
0
0

What will the following JavaScript code do in a WordPress admin page?

medium📝 component behavior Q13 of 15
Wordpress - Content Management
What will the following JavaScript code do in a WordPress admin page?
const frame = wp.media({ title: 'Select Image', multiple: false });
frame.open();
AThrow a JavaScript error because wp.media() is undefined
BUpload a new image automatically without user interaction
CClose any open media uploader popup
DOpen the WordPress media uploader popup allowing single image selection
Step-by-Step Solution
Solution:
  1. Step 1: Understand wp.media() usage

    The code creates a media frame with a title and disables multiple selection, then opens the media uploader popup.
  2. Step 2: Analyze each option

    Open the WordPress media uploader popup allowing single image selection matches the behavior. Upload a new image automatically without user interaction is wrong because it does not upload automatically. Close any open media uploader popup is incorrect as it opens, not closes. Throw a JavaScript error because wp.media() is undefined would happen only if scripts are not loaded.
  3. Final Answer:

    Open the WordPress media uploader popup allowing single image selection -> Option D
  4. Quick Check:

    wp.media() + open() = open media popup [OK]
Quick Trick: wp.media() with open() shows media popup [OK]
Common Mistakes:
  • Assuming it uploads files automatically
  • Confusing open() with close()
  • Not enqueuing media scripts causing errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes