I know, “plugin” sounds like overkill because it’s a big word. But all a plugin really does it modifies/amends discourse’s code, which is exactly what you’re trying to do, right? Of course you can do so much more with plugins than change 2 lines of code, but changing those two lines is entirely possible and not overkill at all. It’s pretty much the same as what you’ve tried, only the “proper” way. It’s so easy that even I was able to do it:
Check out that topic and see if you can make it work for your case.