Theme Customizer changes are dissappearing when change page

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?

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";      
      break;
    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";       
         break;
    default:
    case 'content-sidebar':
        $anatema_layout["primary_class"] = "span8";
        $anatema_layout["primary_fullwidth_class"] = "span12";
        $anatema_layout["secondary_class"] = "span4";       
        $anatema_layout["container_class"] = "container";       
       break;   
}

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 
} 

Leave a Comment