Identifying tags with no content tagged For my job site, jobs are tagged from terms of Tags vocabulary where new ones can be added. Sooner jobs expire and new arrive.

That has resulted in bloated taxonomy vocabulary with 2400 terms (or 2400 pages). I guess many remain empty for long periods.

Many tag pages simply show no classified content available which has attracted Google's Panda penalty.

What I want is removing those tags not used for any node, and automatically deleted those that have not been used in the past 3 months or so get.

Is there any simple way for doing this?
I have a similar script that I use, but I run it as a drush scr.  You can adapt it for your needs, perhaps to do this in a hook_cron():

$tags = taxonomy_vocabulary_machine_name_load('tags');

$tids = db_query('
  SELECT DISTINCT t.tid
  FROM {taxonomy_term_data} t
  LEFT JOIN {taxonomy_index} i ON i.tid = t.tid
  WHERE t.vid = :vid
    AND i.tid IS NULL
', array(':vid' =&gt; $tags-&gt;vid))-&gt;fetchCol();

if (!empty($tids)) {
  foreach ($tids as $tid) {
    taxonomy_term_delete($tid);
  }

  watchdog('foo', 'deleted @count orphaned tags', array(
    '@count' =&gt; count($tids),
  ), WATCHDOG_NOTICE);
}


This exact version is untested and a hand-edit from a very specific use-case I have.  Take backups and use at your own risk!

The only problem is that {taxonomy_term_data} doesn't have a created column, so this will immediately delete orphaned terms.  It also doesn't take into term hierarchy, or tags being on entities other than nodes.