0
0
Wordpressframework~20 mins

Theme customizer in Wordpress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Theme Customizer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this WordPress Theme Customizer code?
Consider this code snippet added to functions.php to add a color setting and control in the Theme Customizer. What will the user see in the Customizer panel?
Wordpress
<?php
function mytheme_customize_register($wp_customize) {
  $wp_customize->add_setting('header_textcolor', [
    'default' => '#000000',
    'transport' => 'refresh',
  ]);
  $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'header_textcolor_control', [
    'label' => __('Header Text Color', 'mytheme'),
    'section' => 'colors',
    'settings' => 'header_textcolor',
  ]));
}
add_action('customize_register', 'mytheme_customize_register');
?>
AA text input labeled 'Header Text Color' appears under the 'Colors' section in the Customizer.
BNo new control appears because 'transport' is set to 'refresh'.
CAn error occurs because 'header_textcolor' is a reserved setting name.
DA new color picker labeled 'Header Text Color' appears under the 'Colors' section in the Customizer.
Attempts:
2 left
💡 Hint
Think about what WP_Customize_Color_Control does and where it appears.
state_output
intermediate
1:30remaining
What is the value of the setting after this Customizer interaction?
Suppose the Theme Customizer has a setting 'background_color' with default '#ffffff'. The user changes it to '#ff0000' but does not click 'Publish'. What is the value of get_theme_mod('background_color') when accessed in the front-end?
A'#ffffff' (the default value)
Bnull because the setting is not saved yet
C'#ff0000' (the new value the user selected)
DAn error because the setting is not published
Attempts:
2 left
💡 Hint
Remember when changes in the Customizer become active on the live site.
📝 Syntax
advanced
2:30remaining
Which option correctly adds a live preview for a text setting in the Theme Customizer?
You want to add a setting 'footer_text' that updates live in the preview without page reload. Which code snippet correctly sets this up?
A
$wp_customize-&gt;add_setting('footer_text', ['default' =&gt; '', 'transport' =&gt; 'live']);
$wp_customize-&gt;add_control('footer_text', ['label' =&gt; 'Footer Text', 'section' =&gt; 'title_tagline']);
B
$wp_customize-&gt;add_setting('footer_text', ['default' =&gt; '', 'transport' =&gt; 'refresh']);
$wp_customize-&gt;add_control('footer_text', ['label' =&gt; 'Footer Text', 'section' =&gt; 'title_tagline']);
C
$wp_customize-&gt;add_setting('footer_text', ['default' =&gt; '', 'transport' =&gt; 'postMessage']);
$wp_customize-&gt;add_control('footer_text', ['label' =&gt; 'Footer Text', 'section' =&gt; 'title_tagline']);

// JS listens for changes and updates footer text live.
D
$wp_customize-&gt;add_setting('footer_text', ['default' =&gt; '']);
$wp_customize-&gt;add_control('footer_text', ['label' =&gt; 'Footer Text', 'section' =&gt; 'title_tagline']);
Attempts:
2 left
💡 Hint
Look for the transport method that enables JavaScript live preview.
🔧 Debug
advanced
2:30remaining
Why does this Customizer control not appear in the panel?
This code is added to functions.php but the control does not show in the Customizer. What is the cause?
Wordpress
<?php
function mytheme_customize_register($wp_customize) {
  $wp_customize->add_setting('sidebar_position', [
    'default' => 'right',
    'transport' => 'refresh',
  ]);
  $wp_customize->add_control('sidebar_position_control', [
    'label' => __('Sidebar Position', 'mytheme'),
    'section' => 'layout',
    'settings' => 'sidebar_position',
    'type' => 'radio',
    'choices' => [
      'left' => 'Left',
      'right' => 'Right'
    ],
  ]);
}
add_action('customize_register', 'mytheme_customize_register');
?>
AThe 'layout' section does not exist by default, so the control is not displayed.
BThe control ID 'sidebar_position_control' must match the setting ID 'sidebar_position'.
CThe 'choices' array keys must be integers, not strings.
DThe 'type' => 'radio' is invalid; it should be 'select'.
Attempts:
2 left
💡 Hint
Check if the section you add the control to exists by default.
🧠 Conceptual
expert
3:00remaining
Which statement about the Theme Customizer's selective refresh is true?
Selective refresh allows parts of the preview to update without a full reload. Which of these statements is correct about how to implement selective refresh for a setting?
ASelective refresh works automatically for all settings with 'transport' => 'refresh' without extra code.
BYou register a partial with <code>$wp_customize->selective_refresh->add_partial()</code> specifying the selector and a render callback.
CSelective refresh requires setting 'transport' => 'postMessage' and no PHP render callback.
DSelective refresh is deprecated and replaced by live preview with JavaScript only.
Attempts:
2 left
💡 Hint
Think about how selective refresh targets specific parts of the preview.