WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I created a button in the theme customizer and I want to use it to execute a function? All I can find is using controls to add theme settings such as CSS and text. Although this button is to clear out all of the settings.

I need it to execute this code:

   <?php remove_theme_mods() ?>

I basically just need to link them together. Can anyone assist?

*EDIT:*Here is the custom control I created for the button I want to access the remove theme mods function:

function newtheme_customize_reset_control($wp_customize) {
     * Reset Control
    class newtheme_Customize_reset_Control extends WP_Customize_Control {
        public $type = 'button';

        public function render_content() {
                        <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
                                    <a href="#" class="button-secondary upload"><?php _e( 'Reset Settings' ); ?></a>

add_action( 'customize_register', 'newtheme_customize_reset_control', 1, 1 );

As stated previously I am hoping to reset all theme mods with this button, although there isn't much on how to do it.

Here is the code I have added the button and section with:

 * Clear theme mod settings
 * Clears all theme modification options/settings in current theme.
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 * @return void

function newtheme_customize_register_clear_settings( $wp_customize ) {

    $theme = wp_get_theme();

    $wp_customize->add_section( 'newtheme_clear', array(
        'title'      => sprintf( __( '%s Reset settings', 'newtheme' ), $theme->Name ),
        'priority'   => 205,
    ) );

    $wp_customize->add_setting( 'newtheme_clear_settings', array(
        'default'    => newtheme_theme_mod( 'clear_settings' )
    ) );

    $wp_customize->add_control( new newtheme_Customize_reset_Control( $wp_customize, 'newtheme_clear_settings', array(
        'label'      => __( 'Reset all settings back to their defaults. Once this is done it cannot be reversed.', 'newtheme' ),
        'section'    => 'newtheme_clear',
        'settings'   => 'newtheme_clear_settings',
        'type'       => 'button',
        'priority'   => 10
    ) ) );      

        do_action( 'newtheme_customize_clear_settings', $wp_customize );

    return $wp_customize;

share|improve this question
Please post all of the relevant code. – s_ha_dum Apr 24 '13 at 4:11
@s_ha_dum Thank you for replying. I have been trying to figure this out and I haven't gotten anywhere. Any help at all is good help. I have added all of the relevant code. – user1632018 Apr 24 '13 at 4:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.