In Drupal 7 there was taxonomy_vocabulary_delete($vid), but this doesn't seem to be there in Drupal 8.

What's the equivalent code for Drupal 8?

3 Answers 3


I believe I have figured this out. You have to load the vocabulary using the Vocabulary entity class, then call the delete method on it. So something like this:


  • But how do you delete by vocabulary name? Commented Aug 4, 2016 at 18:27
  • 1
    In Drupal 8, the vocabulary ID is the machine name of the vocabulary. The shown code is doing already that.
    – apaderno
    Commented Aug 31, 2016 at 8:41
  $tids = \Drupal::entityQuery('taxonomy_term')
    ->condition('vid', 'tags')

  $controller = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
  $entities = $controller->loadMultiple($tids);


     $vid = 'tags';
      $tids = Drupal::entityQuery('taxonomy_term')
          ->condition('vid', $vid)
      entity_delete_multiple('taxonomy_term', $tids);

Here is how I did it

$vocabularies = [
foreach ($vocabularies as $vocabulary) {
    $vocab = Drupal\taxonomy\Entity\Vocabulary::load($vocabulary);
    if ($vocab) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.