Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use delete_theme action in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
April 21, 2023
5 minutes read
So, you’ve decided to delve into the world of WordPress hooks? Superb choice! Today, we’re diving into the delete_theme action hook, a neat little feature that fires just before a theme is deleted. As a fellow developer, let me tell you, this hook can be super useful. You’ll want to register it using add_action, and you can pop this into your functions.php file or, better yet, a custom plugin. Trust me, keeping your hooks in a plugin prevents headaches when you update your theme. And if you ever need to unregister it, remove_action is your buddy.

Parameters

Here’s the parameter you’ll need:

  • $stylesheet: (string) The stylesheet of the theme to delete.

Live Example 1: Basic Hook Registration

This example demonstrates the basic use of the delete_theme hook.

        function weplugins_execute_on_delete_theme_event($stylesheet){
            // Execute code when the theme is deleted
        }
        // add the action
        add_action("delete_theme", "weplugins_execute_on_delete_theme_event", 10, 1);
        

Live Example 2: Hook with Custom Functionality

Here’s how you can add custom functionality when a theme is deleted.

        function weplugins_custom_theme_deletion($stylesheet){
            // Custom functionality on theme deletion
            // Log the deletion or send an alert
        }
        add_action("delete_theme", "weplugins_custom_theme_deletion", 10, 1);
        

Live Example 3: Removing a Hook

If you need to remove your hook, here’s how:

        remove_action("delete_theme", "weplugins_execute_on_delete_theme_event", 10, 1);
        

Ensure you use the same callback function name, priority, and number of arguments.

Access Premium WordPress Plugins

Contact Us

If you need any customization or have questions about using this hook, feel free to contact us. Our team at WePlugins is always ready to assist you.

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.