Skip to content

Instantly share code, notes, and snippets.

@alexstandiford
Last active November 20, 2023 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexstandiford/ed9137a7cf5472c86f1d24cb1f3e46b8 to your computer and use it in GitHub Desktop.
Save alexstandiford/ed9137a7cf5472c86f1d24cb1f3e46b8 to your computer and use it in GitHub Desktop.
<?php
add_action('after_switch_theme', function(){
// Set a flag indicating a new installation
set_theme_mod('theme_version', '1.2.3');
});
// Upgrade routine for backwards compatibility with pre-existing home screen setup.
add_action('init', function() {
// Check if the update logic has already been executed
if (version_compare(get_theme_mod('theme_version'), '1.2.3', '<')) {
// This is either a first run or a theme update
set_theme_mod('is_backcompat_home_screen', true);
// Set the flag to indicate that update logic has been executed
set_theme_mod('theme_version', '1.2.3');
}
});
add_filter('template_include', function($template){
if(get_theme_mod('is_backcompat_home_screen') && is_home()){
$template = locate_template(['index.php']);
}
return $template;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment