0

I've created a custom customizer section for my client to set their contact phone number by using this snippet:

function header_ctas ( $wp_customize ) {

  $wp_customize->add_section( 'cta_section' , array(
    'title'         => 'Call to action buttons',
    'description'   => 'Configure the cta buttons in here for mobile screen',
    'priority'      => 30,
  ) );

  $wp_customize->add_setting( 'cta_settings' );

  $wp_customize->add_control( 'phone_control' , array(
    'label'         => 'Phone number',
    'description'   => 'enter the phone number here, it will appear in mobile screen',
    'section'       => 'cta_section',
    'settings'      => 'cta_settings',
    'type'          => 'text',
  ) );
}
add_action( 'customize_register', 'header_ctas' );

I can retrieve the value of the phone number by get_theme_mod('cta_settings').

After that, I want to properly name the settings, so I just change the cta_settings to phone_settings, and when I try to retrieve the value by get_theme_mod('phone_settings'), it returns nothings. It turns out that the real setting name is still the cta_settings, and after I delete the whole function, the value is still there.

I also tried to use $wp_customize->remove_control("phone_control"); and $wp_customize->remove_section( 'cta_section' );, it basically removes the section and it doesn't remove the value.

I also tried to find out how to deregister the custom theme customizer and to find where the value is in database but no luck :(

Can anyone point me a right direction to dig deeper? Thanks.

0

You have the value stored in the database in the cta_settings theme mod. If you want to rename your setting, then you'll need to move the theme mod data you have stored in the database. For example:

if ( get_theme_mod( 'cta_settings' ) ) {
    set_theme_mod( 'phone_settings', get_theme_mod( 'cta_settings' ) );
    remove_theme_mod( 'cta_settings' );
}
  • It looks like the remove_theme_mod is the one I am looking for, I will try this out, thanks in advance. – Speir Jul 15 '17 at 23:18

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.