Skip to content

Instantly share code, notes, and snippets.

@grex22
Created February 6, 2013 15:48
Show Gist options
  • Save grex22/4723427 to your computer and use it in GitHub Desktop.
Save grex22/4723427 to your computer and use it in GitHub Desktop.
WordPress code for displaying all unused page templates. Great for cleaning out a bloated site with lots of old page templates!
$pages = get_posts('post_type=page&showposts=-1&post_status=any');
$tarray = array();
foreach($pages as $p){
$tarray[] = get_post_meta($p->ID, '_wp_page_template', true);
}
$used = array_unique($tarray);
$all = array();
include_once ABSPATH . 'wp-admin/includes/theme.php';
$templates = get_page_templates();
foreach ( $templates as $template_name => $template_filename ) {
$all[] = $template_filename;
}
$diff = array_diff($all,$used);
print_r($diff);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment