Skip to content

Instantly share code, notes, and snippets.

@sabrina-zeidan
Created July 22, 2017 15:00
Show Gist options
  • Save sabrina-zeidan/5bdd054c275fef64fec815c5627c7241 to your computer and use it in GitHub Desktop.
Save sabrina-zeidan/5bdd054c275fef64fec815c5627c7241 to your computer and use it in GitHub Desktop.
Bulk delete unused tags [Wordpress]
function delete_empty_tags(){
$tags = get_tags( array('number' => 0,'hide_empty' => false));
foreach ( $tags as $tag ) {
$tag_count = $tag->count;
if ($tag_count < 1 ){
wp_delete_term( $tag->term_id, 'post_tag' );
}
}
}
add_action( 'wp_head', 'delete_empty_tags' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment