Change tagged links to custom pathnames

Use case: You have tagged a lot of projects with the names of the responsible creatives. Default behaviour on tag click is a page generated with all the projects (posts) people are linked to. But if you would like to link the tags to each creative's personal page instead things can get nasty. Here's how to do it.  

Y.all('a[href*="/project/?tag="]').each(function(link){// you may add classname there to 'a[href*="?tag="]' or modify selector to fit you needs
  var tag = decodeURI(link.get('search').split('tag=')[1]).toLowerCase().replace(/[\W]+/g,'-');// get the tag, decode url, lowercase, replace all non alph-numeric with '-'
  link.setAttribute('href', '/creative/'+tag);// set new href

Example. A post within the blog project is tagged with Mirjam Berg. The default link for that tag will be "/?tag=Mirjam+Berg". If you run this script in the Footer injection it will change the URL into "/creative/mirjam-berg".

This script is written by the amazing Michael at