Register theme customizer settings when theme activates

I’ve been following this great tutorial (http://wp.tutsplus.com/tutorials/theme-development/digging-into-the-theme-customizer-overview/) and now I have set the Theme customizer.

As far as I understand the settings I assign in the customizer are saved in the database every time the user “saves” in the theme customizer page. Which means that after activating the theme for the first time and before going to the customizer, the settings are not saved.

Read More

My question is, How can I save the settings just after the user activates the theme? (the $wp_customize->add_setting default value)

Pd. I’ve been looking for some time, and got this hooks: “after_setup_theme”, “switch_theme”, but I cant figure out how to do it.

Edit: The “duplicate question” answers how to provide a fallback when there is no setting available. Although it might be a workaround, I would like to know how to save (register) the settings when activating the theme.

Related posts

1 comment

  1. You need only use the default value on the wp_customize and that is all

    $wp_customize->add_setting('mytextoption', array(
        'default'        => 'defaultvalue',
        'capability'     => 'edit_theme_options',
        'type'           => 'option',
    

    replace defaultvalue for the value you want, and when the user activate the theme this line will register the default value on the DB only when not exist on the DB

Comments are closed.