Programmatically creating taxonomy terms in Drupal


Because sometimes you need to roll out a bunch of taxonomy terms across 26 sites, and you just don't feel like clicking those buttons.


$terms = [
    'Case Study',
    'Application Note',
    'Data Sheet',

$vocab = taxonomy_vocabulary_machine_name_load('vocab_machine_name');

foreach($terms as $term) {
    $t = new stdClass;
    $t->name = $term;
    $t->vid = $vocab->vid;

Save this to something like create_terms.php and then run it with drush!

$ drush @site scr path/to/create_terms.php