How Can I Create a List of Values to Be Iterated Through via WordPress Customization API?

Assuming you have an array $locations available, you can use this code to generate a dropdown in the customizer. It’s not that different from a single value. $section_name=”wpse213980_section_name”; // adapt to your naming system $section_title=”wpse213980_section_title”; // adapt to your naming system $setting_name=”wpse213980_setting_name”; // adapt to your naming system $setting_field_type=”select”; $setting_field_options = $locations; $sanitize_callback = ‘sanitize_text_field’; … Read more

Change “Display Site Title and Tagline” checkbox text in theme customizer

You will need to de-register that control. It will look like this: /** * Remove parts of the Options menu we don’t use. * * @param WP_Customize_Manager $wp_customize Customizer manager. */ function de_register( $wp_customize ) { $wp_customize->remove_control(‘display_header_text’); } add_action( ‘customize_register’, ‘de_register’, 11 ); For more information, this Theme Customization is a good start.

Partial refresh of menu in customizer not working?

Selective refresh is only for the items that are selected to cause auto refresh in customizer as explained here: https://make.wordpress.org/core/2016/02/16/selective-refresh-in-the-customizer/ and here: https://make.wordpress.org/core/2016/03/22/implementing-selective-refresh-support-for-widgets/ So if the theme developer haven’t included this support then you might not see it refresh automatically on save and publish of menu items.

Removing pre existing menu item

Here you go: $wp_customize->remove_section(‘colors’); $wp_customize->remove_section(‘nav_menus’); $wp_customize->remove_section(‘static_front_page’); EDIT AFTER DISCUSSION After testing I found that this doesn’t work for nav_menus. You have to set a higher priority on the hook, like this: add_action( ‘customize_register’, ‘remove_nav_menu_section’, 20 ); This gives a php warning from WP but otherwise does the job.

JavaScript in WordPress Customizer

This is because you are using wp_kses_post to sanitize the output data, try without it: <?php echo get_theme_mod( ‘script-code’); ?> also remove it from here: $wp_customize->add_setting ( ‘script-code’, array ( ‘default’ => esc_html__( ‘Script Code’, ‘x’ ), ‘sanitize_callback’ => ” // remove wp_kses_post ) ); also make sure you are using the right name of … Read more

WordPress Customizer sanitize_callback: How to Reset to Default on Fail

In the sanitize_callback function you can look at the second argument which is the WP_Customize_Setting instance and access the default property there when returning due to an empty provided value: add_action( ‘customize_register’, function( WP_Customize_Manager $wp_customize ) { $wp_customize->add_setting( ‘facebook_url’, array( ‘default’ => ‘https://www.facebook.com/USERNAME’, ‘sanitize_callback’ => function( $url, $setting ) { if ( empty( $url ) … Read more