Bird
0
0

You want to add a dropdown control in the Theme Customizer to select a font family with options 'Arial', 'Georgia', and 'Verdana'. Which code snippet correctly achieves this?

hard📝 Application Q8 of 15
Wordpress - Themes and Appearance
You want to add a dropdown control in the Theme Customizer to select a font family with options 'Arial', 'Georgia', and 'Verdana'. Which code snippet correctly achieves this?
A$wp_customize->add_setting('font_family', ['default' => 'Arial']); $wp_customize->add_control('font_family', ['type' => 'text', 'section' => 'typography', 'label' => 'Font Family']);
B$wp_customize->add_setting('font_family', ['default' => 'Arial']); $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'font_family', ['section' => 'typography', 'label' => 'Font Family']));
C$wp_customize->add_setting('font_family', ['default' => 'Arial']); $wp_customize->add_control('font_family', ['type' => 'radio', 'section' => 'typography', 'choices' => ['Arial', 'Georgia', 'Verdana'], 'label' => 'Font Family']);
D$wp_customize->add_setting('font_family', ['default' => 'Arial']); $wp_customize->add_control('font_family', ['type' => 'select', 'section' => 'typography', 'choices' => {'Arial': 'Arial', 'Georgia': 'Georgia', 'Verdana': 'Verdana'}, 'label' => 'Font Family']);
Step-by-Step Solution
Solution:
  1. Step 1: Identify control type for dropdown

    The 'select' type creates a dropdown with multiple choices.
  2. Step 2: Check choices format

    Choices must be an associative array with keys and labels; $wp_customize->add_setting('font_family', ['default' => 'Arial']); $wp_customize->add_control('font_family', ['type' => 'select', 'section' => 'typography', 'choices' => ['Arial' => 'Arial', 'Georgia' => 'Georgia', 'Verdana' => 'Verdana'], 'label' => 'Font Family']); uses correct format.
  3. Step 3: Verify other options

    $wp_customize->add_setting('font_family', ['default' => 'Arial']); $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'font_family', ['section' => 'typography', 'label' => 'Font Family'])); uses color control incorrectly; C uses radio with wrong choices format; A uses text input instead of dropdown.
  4. Final Answer:

    Code snippet with 'select' type and associative choices array -> Option D
  5. Quick Check:

    Dropdown needs 'select' type and choices array [OK]
Quick Trick: Use 'type' => 'select' and 'choices' array for dropdowns [OK]
Common Mistakes:
  • Using color control for non-color settings
  • Incorrect choices array format
  • Using 'text' instead of 'select' for dropdown

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes