As long as you don’t delete your theme by ftp, but use the regular way of switching to another theme in the admin, there is a hook to use, switch_theme
. It works like this:
add_action('switch_theme', 'mytheme_setup_options');
function mytheme_setup_options () {
delete_option('mytheme_option1');
delete_option('mytheme_option2');
}
There’s a sister hook called after_switch_theme
, which you could use, for instance, to load default options when a theme is switched on.
Related Posts:
- How to display message (with switch_theme hook) after deactivating My theme?
- What hook is the currently active theme’s functions.php file loaded on? [duplicate]
- Opinions and recommendations on the best barebones base theme [closed]
- How can I edit post data before it is saved?
- Customizing a WordPress theme without changing it?
- get_template_part vs action hooks in themes
- How to Link External jQuery/Javascript files with WordPress
- Custom Taxonomy-specific JavaScript
- Issue with get_theme_mod returning a blank value instead of the saved value
- Any official way to create an admin theme?
- Splitting an Evolving Site into Multiple Sites, or Maintaining as One Site?
- Check php version before theme activation
- What’s the earliest point I can get the queried object ID?
- Building useful features into your theme
- Multisite: setting theme and options when a new blog is created
- How can I remove “Proudly powered by WordPress” from twentyeleven without modifying footer.php?
- Editing theme files and access to the Code pages only to super-admin?
- Change Default Image HTML
- Remove action within a class in a parent theme from the child theme
- How to delete default themes
- Extra User Profile Field Upload File / Image
- Edit raw HTML of the landing page
- Print shortcode in custom action hook not where the shortcode is entered
- Problem : deletion failed, the theme requested does not exist
- Theme Activation, Create Database Tables
- Disable email field on WooCommerce customer account details
- Will activating a different theme preserve custom settings to current theme?
- Can I apply a WP theme to a specific custom page template?
- Delete database tables on theme uninstall?
- Setting a static home page and blog page without using the settings
- Two Navigation Menus – secondary nav is including main nav
- Possible to put header-{your_custom_template}.php in subdirectory?
- Renaming the Twenty Fourteen WordPress theme
- add_action in functions.php, do_action in plugin?
- Protect changes made to the theme when updating
- Theme Development Admin Area [closed]
- How to set a single theme directory on a multisite blog?
- Hooking into the init action will fire it too frequently?
- Static page not working
- Custom options below pages/posts editor?
- How can I add class to every quote element?
- Adding buttons to Add New Post and Add New Page
- Modify custom field input data before creating a new post
- Redux callback action
- Problem of running development copy of WordPress on WebMatrix?
- Different logo on homepage
- the_content() is not displaying content, why? [closed]
- What is the correct way to integrate wordpress with another php application?
- Customizing page content layout
- Tips for managing code when developing a parent theme framework
- after_setup_theme is called three times
- It’s okay if I do not write add_action()
- Is it good practice moving the main stylesheets after the plugin styles?
- How to cancel an action hooked to untrash_post? or any hook
- Plugin Development – Functions or Hooks?
- How to get menu location in wp_update_nav_menu hook
- Trying to uninstall a theme, but it’s hijacking my home page
- Most wp_nav_menu parameters ignored
- Using the same database on another Subdomain
- Advanced WordPress plugin activation detection
- How To Show Different Footers For Different Post Types Pages?
- How to include stylesheet in custom admin using parent_slug
- Custom fields not displaying on front end
- My blog suddenly can’t find my stylesheet?
- Fix warning: Missing argument
- Customizing 1 theme for multiple blogs in a multisite setup
- Is there any way to modify images from a theme using the web interface?
- How can Use custom input field in functions.php page?
- Save_post – Warning: Cannot modify header information
- Set custom directory in theme for page templates
- Hooking into the HTML header container
- Webflow Interactions on WordPress site?
- Don’t prepend WordPress base url to image paths
- Default and warning messages & no login
- Check get_post value after wp-admin login
- dynamic image path within a javascript file
- wp_login_form() ignoring login_form action hook
- Display ads by location [closed]
- WordPress Dashboard Problem [closed]
- Theme Dev | Convert Template to Theme
- Warning: call_user_func() expects parameter 1 to be a valid callback
- Are immediately-called actions not usable in themes?
- Work on theme files on a server & browser preview before installing it
- How to remove the option data of a theme when that theme is removed?
- Create a child Theme or custom Theme
- Redirect back to origin page after using get_delete_post_link()
- Theme Options Menu Item – Permission Issue
- How wordpress plugin hooks works? [duplicate]
- Static front page displaying twice
- Where can I find the “add_action()” inside a theme?
- Adding a wp_head hook from an included PHP file
- Static posts page is not working
- Fatal error Class-wp-hook, again, but not sure what’s triggering it
- Switching themes without losing widgets?
- Is there a recover_post hook to go with trash_post hook?
- WordPress Ajax Problems
- Problem only while using require_once() within functions.php
- wordpress-theme 2017: featured image behaviour: where to set the height of the featured image?
- Why the output of an image gallery plugin is not displayed into a page of my custom theme?
- How to make a page extend full screen [closed]