I have recently starting integrating the wordpress customizer into my theme.

Given the fact that i already had a theme options page, i use these values as default values of my new options (in the add_setting parameter).

All my new options are held into a variable called 'theme_options' which is an array of values.

The problem i have is that a user has to visit the customization page and click "save" on his first install to populate the 'theme_options' variable.

I am wondering if there is a way to initialize this field on theme activation directly (just like many theme options framework do).

Thanks in advance !

1 Answer 1


I believe that all you need to do is pass defaults to get_option

function init_theme_options() {
  // check to see if theme options are set
  // Not sure how your options are organized but...
  $defaults = array(
    'opt1' => 'stuff1',
    'opt2' => 'stuff2'
  $theme_options = get_option('theme_option_name',$defaults);

If you want to see a very complicated version of this, look at how Twenty Eleven does it.

  • Thank you ! I think you're right, it should be done with get_option.
    – gnrocks
    Commented Jan 16, 2013 at 4:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.