Bird
0
0

Given this code snippet in a Theme Customizer setup:

medium📝 state output Q13 of 15
Wordpress - Themes and Appearance
Given this code snippet in a Theme Customizer setup:
 $wp_customize->add_setting('header_text', [
  'default' => 'Welcome!',
  'sanitize_callback' => 'sanitize_text_field'
]);
$wp_customize->add_control('header_text', [
  'label' => 'Header Text',
  'section' => 'title_tagline',
  'type' => 'text'
]);
What will get_theme_mod('header_text') return if the user has not changed the setting?
AAn empty string
Bnull
CAn error message
D'Welcome!'
Step-by-Step Solution
Solution:
  1. Step 1: Check the default value in add_setting()

    The setting 'header_text' has a default value of 'Welcome!'.
  2. Step 2: Understand get_theme_mod behavior

    If the user has not changed the setting, get_theme_mod() returns the default value.
  3. Final Answer:

    'Welcome!' -> Option D
  4. Quick Check:

    Default value returned by get_theme_mod() = 'Welcome!' [OK]
Quick Trick: get_theme_mod returns default if no user change [OK]
Common Mistakes:
  • Assuming it returns null if unset
  • Expecting empty string instead of default
  • Thinking it throws an error without user input

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes