Delete empty tags in WordPress

Apply this code in functions.php of the current theme:

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' );

Leave a comment

Your email address will not be published. Required fields are marked *