This is how WordPress works. It’s fundamental and has nothing to to do with the theme. When I take it a theme, I modify the heck out of it.
Embedding the code into individual pages is the long way.
Creating a widget via Appearance > Widgets (not the block editor in the post/page) means that the code is pasted only once and appears on every post/page where you want it to appear.
In fact, this PDF plugin (as opposed to the code version we’ve been debating) uses conditionals using check boxes. You choose where you want the code to appear, and the options are, among others, posts and pages.