Customizer Does Not Work

Hi there, I am trying to add settings to the WP customizer, I have tried to add panels, sections, etc… and none of them appear. These are the only settings that show up:

My customizer function is based off of some sample code:

function customize_register($wp_customize) {
  $wp_customize->get_setting('blogname')->transport = 'postMessage';

  /*
   * Failsafe is safe
   */
  if ( ! isset( $wp_customize ) ) {
    return;
  }
  echo get_theme_mod('widget_list_style');

  /**
   * Add Panel for General Settings.
   *
   * @uses $wp_customize->add_panel() https://developer.wordpress.org/reference/classes/wp_customize_manager/add_panel/
   * @link $wp_customize->add_panel() https://codex.wordpress.org/Class_Reference/WP_Customize_Manager/add_panel
   */
  $wp_customize->add_panel(
    // $id
    'theme_slug_panel_general',
    // $args
    array(
      'priority'            => 10,
      'capability'      => 'edit_theme_options',
      'theme_supports'  => '',
      'title'           => __( 'Theme Name General Settings', 'theme-slug' ),
      'description'         => __( 'Configure general settings for the Theme Name Theme', 'theme-slug' ),
    )
  );
  /**
   * Add Panel for Color and Layout Settings.
   *
   * @uses $wp_customize->add_panel() https://developer.wordpress.org/reference/classes/wp_customize_manager/add_panel/
   * @link $wp_customize->add_panel() https://codex.wordpress.org/Class_Reference/WP_Customize_Manager/add_panel
   */
  $wp_customize->add_panel(
    // $id
    'theme_slug_panel_colorslayouts',
    // $args
    array(
      'priority'            => 11,
      'capability'      => 'edit_theme_options',
      'theme_supports'  => '',
      'title'           => __( 'Theme Name Colors and Layouts', 'theme-slug' ),
      'description'         => __( 'Configure color and layout settings for the Theme Name Theme', 'theme-slug' ),
    )
  );
  /**
   * Add Panel for Advanced Settings.
   *
   * @uses $wp_customize->add_panel() https://developer.wordpress.org/reference/classes/wp_customize_manager/add_panel/
   * @link $wp_customize->add_panel() https://codex.wordpress.org/Class_Reference/WP_Customize_Manager/add_panel
   */
  $wp_customize->add_panel(
    // $id
    'theme_slug_panel_advanced',
    // $args
    array(
      'priority'            => 12,
      'capability'      => 'edit_theme_options',
      'theme_supports'  => '',
      'title'           => __( 'Theme Name Advanced Settings', 'theme-slug' ),
      'description'         => __( 'Configure advanced settings for the Theme Name Theme', 'theme-slug' ),
    )
  );
}
add_action('customize_register', __NAMESPACE__ . '\\customize_register');

From what I understand of using the customizer, you must add a setting and a control to a section for the section to actually show up. In other words, you’ve created a few panels with titles and descriptions but there’s no controls associated with them yet.

Here’s a sample of a section, option and control that’s working for me:

$wp_customize->add_section( 'footer_section', array( 'title' => 'Footer Settings', 'description' => 'Edit the footer area.', 'priority' => 55, ) ); $wp_customize->add_setting( 'copyright_textbox', array( 'default' => 'Copyright © 2016. All Rights Reserved.', ) ); $wp_customize->add_control( 'copyright_textbox', array( 'label' => 'Copyright', 'section' => 'footer_section', 'type' => 'text', ) );

This article helped me out a lot.

2 Likes

I don’t think that failsafe is going to work like you’re thinking. $wp_customize will always be set, since it’s passed in to your function.

A much better check would be

if ( ! $wp_customize instanceof \WP_Customize_Manager) {
  return;
}

However, IMO that’s being extra cautious. The only time the Customizer manager would not be passed in is if you used the function in another hook. No reason to do that though.