Support » Plugins » Hacks » delete_theme example?

Viewing 4 replies - 1 through 4 (of 4 total)
  • jack randall


    just as a side note regarding the default themes that come with wordpress, they are a valuable debugging tool for when things go wrong with wordpress. it might be worth leaving them alone…

    In default, it comes with 3. I always leave 1.


    Plugin Name: wp-forums: delete_theme example?
    Plugin URI:
    Version: 1.0.0
    Author: Aubrey Portwood
    Author URI:
    License: GPL2
    Topic URI:
     * Copyright 2015 Aubrey Portwood <>
     * This program is free software; you can redistribute it and/or modify
     * it under the terms of the GNU General Public License, version 2, as
     * published by the Free Software Foundation.
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * GNU General Public License for more details.
     * You should have received a copy of the GNU General Public License
     * along with this program; if not, write to the Free Software
     * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     * Will delete themes except the one's specified.
     * Note with this implementation, everytime the
     * Dashboard is accessed it deletes all the themes
     * except the ones specified.
     * @author  Aubrey Portwood
     * @since   1.0.0
    function wp_forums_aubreypwd_delete_themes() {
    	// The current themes.
    	$themes = wp_get_themes();
    	// The themes we want to keep (delete the others).
    	$themes_to_keep = array(
    		// Replace this with the theme(s) you created or don't want deleted.
    		'twentyeleven', // Going to leave at least one active.
    	// Loop through installed themes.
    	foreach ( $themes as $theme ) {
    		// This is the name of the theme.
    		$name = $theme->get_template();
    		// If it's not one we want to keep...
    		if ( ! in_array( $name, $themes_to_keep ) ) {
    			$stylesheet = $theme->get_stylesheet();
    			// Delete the theme.
    			delete_theme( $stylesheet, false );
    add_action( 'admin_init', 'wp_forums_aubreypwd_delete_themes' );

    In this example, we specify the themes we want to keep, loop through the themes installed and delete the one’s we haven’t specified to keep. Should help you get started 🙂 Thanks for requesting this, was fun to learn.

    Thanks, but in the meanwhile I’ve found the solution for it already. 😉

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘delete_theme example?’ is closed to new replies.