add_action and wp_head not display content in head section

That code must run before the wp_head hook fires or nothing will happen, and when tested in a mu-plugin file it does work.

I suspect that you are trying to hook that function too late– perhaps from inside a theme template file after get_header (in most cases). Place that code in the theme’s functions.php or in a (mu-)plugin file and it should work at least insofar as echoing content goes. I did not analyze it for other bugs.