Hook Into the_content Filter For JSON API Only [closed]

Your problem is not as much filtering content, as content assuming too much about context and doing things that content shouldn’t really. You don’t read the book where text decides to color itself, it’s decided for it.

I would suggest to consider decoupling content from active context-specific functionality. You can still use shortcodes, but instead of them actively spitting out JavaScript to a page there should be more flexible and do things like setting some “flags” for JS to be output in footer and so on.