A few days ago I stumbled upon this old module, which had been laying in the modules directory of one of my sites since 2017 in a half-finished state. I have no recollection why I left it like that, but figured it might be useful for someone, so here we go:
https://github.com/teppokoivula/Snippets
https://processwire.com/modules/snippets/
Snippets is a tool for injecting front-end code snippets (HTML/JS/CSS) into page content. The way it works is that you create a snippet — say, a Google Analytics tag — and then choose...
which element it should be tied to (there are some pre-populated choices and custom regex option),
whether it should be placed before/after said element or replace it entirely, and
which pages the snippet should apply to.
The "apply to" option also has some ready to use options (such as "all pages" and "all non-admin pages") or you can select specific pages... or use a selector. Snippets are regular markup, with the exception that you can use values from current page (behind the scenes the module makes use of wirePopulateStringTags()).
Available hooks:
Snippets::isApplicable, which receives the snippet object and current Page object as arguments and returns a boolean (true/false).
Snippets::applySnippet, which receives the snippet object, page content (string), variables (an object derived from WireData), and an array of options for wirePopulateStringTags() as arguments and returns the modified page content string.
That's just about it. It's a pretty simple module, but perhaps someone will find this useful ?