1

I upgraded my dev environment to 4.9, and the customizer chokes on my _underscores-based theme. The customizer works fine on TwentySixteen, so I think there is a problem with my theme.

The tell was that the Customizer's Save & Publish button is missing entirely from the UI. Some other strange things happen, like the labels for my settings under the Colors panel are not visible until you click on the color picker.

Firefox dev console says

TypeError: a.elements[0] is undefined [Learn More] load-scripts.php:6:12121

And when I click [Learn more] it shows

<anonymous>
http://localhost/test-site/wp-admin/load-scripts.php:6:12121
i
http://localhost/test-site/wp-admin/load-scripts.php:2:27444
fireWith
http://localhost/test-site/wp-admin/load-scripts.php:2:28213
when/<
http://localhost/test-site/wp-admin/load-scripts.php:2:4062
i
http://localhost/test-site/wp-admin/load-scripts.php:2:27444
add
http://localhost/test-site/wp-admin/load-scripts.php:2:27748
when
http://localhost/test-site/wp-admin/load-scripts.php:2:3810
instance
http://localhost/test-site/wp-admin/load-scripts.php:2:2847
f
http://localhost/test-site/wp-admin/load-scripts.php:2:526
<anonymous>
http://localhost/test-site/wp-admin/load-scripts.php:6:12068
i
http://localhost/test-site/wp-admin/load-scripts.php:2:27444
fireWith
http://localhost/test-site/wp-admin/load-scripts.php:2:28213
ready
http://localhost/test-site/wp-admin/load-scripts.php:2:30004
K
http://localhost/test-site/wp-admin/load-scripts.php:2:30366

The front end seems to be working fine. Is there guidance for theme developers about the changes in the Customizer that 4.9 has delivered? I don't know what I should be looking for.

UPDATE:

I tested this theme on my SiteGround account to make sure the problem wasn't something related to my local machine or server instance. The same issue exists on one of my live sites on SiteGround only after I updated it to 4.9, so I believe this is definitely a problem between my theme and the latest version of WP.

1

I found the line of code in my theme that is breaking the customizer in 4.9. Behold!

$wp_customize->remove_setting( 'header_textcolor' );
0

I can reproduce the same error in 4.8.3 if I try just removing the header_textcolor setting. So I don't see how this is something new introduced in 4.9. The code that is causing the problem can be found in the function that runs for initializing the display_header_text control:

    // Juggle the two controls that use header_textcolor
    api.control( 'display_header_text', function( control ) {
        var last = '';

        control.elements[0].unsync( api( 'header_textcolor' ) );

It's true that this code should be hardened a bit to check for the existence of the header_textcolor setting before running, but in the mean time all you need to do is remove the display_header_text control in addition to removing the header_textcolor setting. Like this:

add_action( 'customize_register', function( WP_Customize_Manager $wp_customize ) {
    $wp_customize->remove_setting( 'header_textcolor' );
    $wp_customize->remove_control( 'display_header_text' );
}, 20 );
  • This is a useful answer, but is not workable in my theme. – rg89 Nov 21 '17 at 19:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.