Thank you! But I only get it to work if I remove the first if state:
if ($page == page('tag-manager')):
How can I be sure that this only run when that page is updated? I realize that I send the tag-manager page to the function so no other page should be affected, but still. feels better to only run this when the page tag-panager is saved.
Maybe the path to the tag-manager page is not correct? But assuming that this page has a unique blueprint, you could change your if statement like this:
if ($page->intendedTemplate()->name() === 'tag-manager') :