Well, I would try moving the code out of the template file “template-hook.php” and insert it at the end of the file called “functions.php”
You can add a plugin like Head, Footer and Post Injections and move the code there
You can check your WordPress theme, it very well may already have a box to add a script to all the pages.
Just note however, if you use the last 2 methods you only add the
<script> code </script> parts, not the php parts.
Actually - sorry - I though you were asking about moving the code I suggested in the first part of your question, but it looks like you are asking an entirely new question. Sorry - my bad…
If you want to add a block of html code to every page, the answer to the question depends on where you want to add it.
If you want it to appear in as part of the body of all the pages you will likely just have to add it to every page inside the page editor.
If the theme you are using has an available widget area in the correct page location then you can simply add a widget like “Custom HTML” ( that comes with all WordPress installations ) and add the html code there. You would need to rewrite the code in your example to remove the php parts,
$page_title = and use only the html/css part.
Whatever you are trying to do, do a little research on “WordPress widgets” if the concept is not familiar to you, then use what you learn to adapt what you are trying to do to make it work.