I just tried manually running document.querySelector("h1.gh-article-title").hidden = true; in my browser console, and the 'About" disappeared appropriately. So I suspect that your event listener isn’t firing. Can you add a console.log('triggered!') into the code injection, to get some more information about whether it’s firing?
The example I see online that looks like what you’re trying to do has this:…
window.addEventListener('DOMContentLoaded', (event) => {
# do stuff })
So if it isn’t firing, try attaching the event listener to the window?
It’s not that the event is not firing–and I’ve tried console.log and it doesn’t go through. It’s that the injection is not appearing in the tag at all for some reason although the tag is added and configured properly.
This took me a second to understand, but here’s the story:
Those code injection fields are for the tag pages themselves, not for posts or pages that have those tags. That means that a code injection for a public tag will run on /tag/slug but not on a post with that slug. For this reason, your approach won’t work.
However, there are other approaches.
Most themes will already include all tags as classes on a post using Ghost’s post class. For a private tag of test, it’ll output a class of hash-tag-test, which you can then target with CSS.
Theme level: Edit your theme to conditionally apply classes based on the presence of the private/internal tag.