How to load this code on function.php

Without any further detail (error messages, etc), we’re just guessing here.

I first thought of the print_my_inline_script() function as being doubly defined, but then it looked to me like you have a <script> within a <script>.

Remove the outside <script> </script> commands and see what that does.