Managing tags in the control panel

Over time, if you have enough people who just don’t pay attention editing your blog articles, you end up with a tag nightmare. Example of some of the tags a client has on their blog:

  • Security
  • security
  • cybersecurity
  • Cybersecurity
  • cyber security

You get the idea. Is there a way to manage tags in the control panel? I’d love to see a list of tags, and be able to do a few different things, with these edits automatically being applied to all the pages that have these tags:

  1. Rename a tag
  2. Merge tags
  3. Move all articles from one tag to another tag

And maybe other things, but those are the big ones. Any way to do this? Manually editing all the text files is going to be a royal pain in the butt.

Well, I don’t think you will be surprised if I tell you that this is not possible out of the box. What you would need is a Panel plugin, maybe a widget or a separate Panel page, but I’d imagine that that would require a bit of development effort.

Hey,
people writing about cybersecurity must surely understand difference between upper/lower case!

Usually when i have this problem its more like:

  • dog
  • Dogs
  • doggo
  • Doggos
  • DOGE
  • wOOfer
  • yaffer
  • puppy
  • pup
  • pupper
  • flapper
  • hound

It is no joke. Those people tagging this believe it is a big difference (reddit would surely agree) but for proper function of the site it is bad. Synonyms are hard and only way around it is to educate the people posting it.

What i am trying to say - uppercase is the smallest problem.

What helped us is to have one page where you can see all the tags so people can pick and do new ones only if there is no alternative. Also if you can have only one person tagging it. This works best because they will figure out the best system themselves and it will be consistent.

Considering uppercase i think you can just force the tag field to make everything lowercase on input. Its probably not possible out of the box (good idea for small improvenment maybe @texnixe?), but it should be very easy when you just copy the core tag field and edit it.

I think for the uppercase/lowercase problem you can just output everything in lowercase and do the filtering in a case-insensitive way, so I don’t think you have to edit the tags field.

You could also think about using a multi-select field instead of a tags field, which gets its options from a site settings field. Maybe not as intuitive but would help preventing such a mess.

You could also have a list of already used tags below the tags field, but if there are many tags, that might get a bit messy.

1 Like

you could create a structure field and access it via a panel.page.create/update hook to apply these automations on event of saving the page.
or consider extending the tags field with a custom field and validator like done here.

this is a code snippet i once used to update some tags applying a fix. you could use something like that to fix existing pages once you custom field is working.

foreach ($site->index()->filter('template', 'post') as $pageToCleanTags) {
	try{
		$tags = $pageToCleanTags->tags()->value();
		$tags = str::lower($tags); // all lowercase
		$tags = str_replace(['cyber security'], ['cybersecurity'], $tags);
		// or some other cleaning code
		$pageToCleanTags->update(['tags'=>$tags]);
	}
	catch(Exception $ex) {
		echo $ex->getMessage();
	}
}
3 Likes

You could in fact create an array of replacement strings and use that with @bnomei’s code above to fix all affected strings.

1 Like

Thanks, I think this will be really useful.