Hi @gschoppe Greg,
I came to realise that the filter of the
To make it work, the filter needs to be replaced with an action:
And the function itself can be simplified by:
You can see, the changes also in my original gist (updated of course with your changes).
What do you think about releasing this together as a plugin in the WP Plugin Repo?