An example option i am using:

     // Layout
    $wp_customize->add_setting( $themeslug.'_settings[layout]', array(
        'default' => 'content-sidebar',
        'type' => 'option',
        'transport'         => 'postMessage'
    ) );             
    $wp_customize->add_control( $themeslug.'_settings[layout]', array(
        'label' => __( 'Layout', 'anatema' ),
        'section' => 'secenek',
        'type' => 'radio',
        'choices' => array(
            'content-sidebar' => __( 'Content - Sidebar', 'anatema' ),
            'sidebar-content' => __( 'Sidebar - Content', 'anatema' ),
    ) );                        
    $wp_customize->get_setting( $themeslug.'_settings[layout]' )->transport = 'postMessage';

My options are getting save when click save button. Changes are effecting properly on live preview with customizer.js but when i click a page in live preview, all un-saved changes are disappearing. How can i prevent that?

  • Not sure, but you don't need that final get_setting command at all. You're already setting the transport as postMessage when you add it.
    – Otto
    Jan 26, 2013 at 21:00
  • well.. i am not sure where i am doing wrong. Normally should it keep changes when page change? can you check theme if i send you theme as zip? Jan 26, 2013 at 21:09
  • You're probably looking in the wrong place. Look at the place where you actually get the setting and use it in the theme. See if there's something funky there.
    – Otto
    Jan 27, 2013 at 1:15
  • Wow.. I think i found problem. It seems wordpress is not calling functions.php file when you refresh page in theme customizer. I will write detailed answer when i am %100 sure about problem and solution Jan 27, 2013 at 5:39

1 Answer 1


With @Otto's tips, i found the problem.

I was calling theme settings in functions.php and was calling settings as global variable in theme files. This was working properly except temporary changes was disappearing in theme customizer's live edit when you change page with clicking links.

After this experience, what i am suggesting:

If you have some functions need to run for theme settings like this one for example:

$anatema_settings = get_option( 'anatema_settings' ); // site options
switch ($anatema_settings["layout"]) {
    case 'only-content':
        $anatema_layout["primary_class"] = "span8";
        $anatema_layout["primary_fullwidth_class"] = "span8";
        $anatema_layout["secondary_class"] = "hide";        
        $anatema_layout["container_class"] = "container";       
        $anatema_layout["page_class"] = "site-narrow";      
    case 'sidebar-content':
        $anatema_layout["primary_class"] = "span8 pull-right";
        $anatema_layout["primary_fullwidth_class"] = "span12";
        $anatema_layout["secondary_class"] = "span4";       
        $anatema_layout["container_class"] = "container";       
    case 'content-sidebar':
        $anatema_layout["primary_class"] = "span8";
        $anatema_layout["primary_fullwidth_class"] = "span12";
        $anatema_layout["secondary_class"] = "span4";       
        $anatema_layout["container_class"] = "container";       

Create a new file and include it to every theme file that need those theme options. Update: Call it in customize_preview_init action like:

add_action( 'customize_preview_init', "firmasite_customizer_preview_init");
function firmasite_customizer_preview_init() {
    include ( get_template_directory() . '/functions/customizer-call.php');         // Customizer functions 
  • "and was calling settings as global variable in theme files" Ahh, yes, that would be your issue. There's no need to attempt to optimize this bit. Call get_options or get_theme_mod to get your settings in your templates or functions instead. WordPress uses in-memory caching for these automatically, and won't be making unnecessary database hits for them when you call these functions. Almost all options and theme_mod settings are already stored in memory by the core cache code by the time the theme runs.
    – Otto
    Feb 5, 2013 at 18:07
  • i updated answer.. we need to add this function file to customize_preview_init thats all Mar 2, 2013 at 17:42

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.