Title: Keep header when switching theme
Last modified: August 20, 2016

---

# Keep header when switching theme

 *  [tonny@debug.dk](https://wordpress.org/support/users/tonnydebugdk/)
 * (@tonnydebugdk)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/keep-header-when-switching-theme/)
 * Hey
 * Im trying to do a plugin that will keep the users header after theme change. 
   So far i come up with this.
 *     ```
       <?php 
   
       add_action('pre_update_option_theme_mods_' . get_option( 'stylesheet' ), save_header_image_as_option);
       add_action('switch_theme', 'keep_header'); 
   
       error_log("stylesheet " . get_option( 'stylesheet' ),0);
       error_log("prevous header " . get_option( 'previous_header_image_saved' ),0);
   
       function save_header_image_as_option()
       {
       	$details_before = get_theme_mods($blog_id);
       	update_option("previous_header_image_saved", get_theme_mod('header_image'));
       	error_log("before theme change" . json_encode($details_before), 0);
       	return $details_before;
       }
   
       function keep_header()
       {
       	$details_after = get_theme_mods($blog_id);
       	set_theme_mod('header_image', get_option("previous_header_image_saved"));
       	error_log("after theme change" . json_encode($details_after), 0);
       	return $details_after;
       }
   
       ?>
       ```
   
 * Sadly it does not work, because the trigger is also triggede when trying to CHANGE
   the header. Any suggestion on how to accomplish to keep header when changing 
   themes ?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Arun Basil Lal](https://wordpress.org/support/users/arunbasillal/)
 * (@arunbasillal)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/keep-header-when-switching-theme/#post-2966976)
 * Hey Tony,
 * Have you figured it out somehow? If so would appreciate how you did that. Thanks!
 *  Thread Starter [tonny@debug.dk](https://wordpress.org/support/users/tonnydebugdk/)
 * (@tonnydebugdk)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/keep-header-when-switching-theme/#post-2966977)
 * Nope still no solution sadly.
 *  Thread Starter [tonny@debug.dk](https://wordpress.org/support/users/tonnydebugdk/)
 * (@tonnydebugdk)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/keep-header-when-switching-theme/#post-2967038)
 * Ended up with this:
 *     ```
       <?php
       /**
        * @package Preserve_Header_Image
        * @version 1.0
        */
       /*
       Plugin Name: Preserve_Header_Image
       Plugin URI: http://bloggersdelight.dk/
       Description: Preserve header image between stylesheet (theme) switchings.
       Version: 1.0.0
       Author: Nikolaj Jørgensen
       Author URI: http://bloggersdelight.dk/
       License: GPLv2 or later
       */
   
       add_action('pre_update_option_stylesheet', 'phi_pre_update_option_stylesheet');
       add_action('switch_theme', 'phi_switch_theme');
   
       function phi_pre_update_option_stylesheet($stylesheet)
       {
               update_option('previous_header_image_saved', get_theme_mod('header_image'));
   
               return $stylesheet;
       }
   
       function phi_switch_theme()
       {
               if (get_option('previous_header_image_saved')) {
                       set_theme_mod('header_image', get_option('previous_header_image_saved'));
                       delete_option('previous_header_image_saved');
               }
       }
       ?>
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Keep header when switching theme’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 3 replies
 * 2 participants
 * Last reply from: [tonny@debug.dk](https://wordpress.org/support/users/tonnydebugdk/)
 * Last activity: [13 years, 9 months ago](https://wordpress.org/support/topic/keep-header-when-switching-theme/#post-2967038)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
