The wp_head action hook is triggered within the <head></head> section of the theme’s header.php template by the wp_head() function.
Although this is theme-dependent, it is one of the most essential theme hooks, so it is widely supported. See the Plugin API Hooks page on the Theme handbook for more information.
WordPress core uses this hook to perform many actions. Most of default actions into the 'wp-head' hook by WordPress core are set up in wp-includes/default-filters.php. If you need to remove a default hook, this file will give you the priority for which to use to remove the hook.
or for inline scripts which need to be placed in the head,
function hook_javascript() {
?>
<script>
alert('Page is loading...');
</script>
<?php
}
add_action('wp_head', 'hook_javascript');
The wp_head() function which ones sees in all header.php files, is simply triggering the hook do_action(‘wp_head’). WordPress core files then hooks it multiple times to print the head,
Warning: Do not use! The shutdown hook fires before PHP shuts down execution. It is always called, even in ajax requests, so this will immediately break your site.
taken from the old codex pages:
or for inline scripts which need to be placed in the head,
The wp_head() function which ones sees in all header.php files, is simply triggering the hook do_action(‘wp_head’). WordPress core files then hooks it multiple times to print the head,
However, more interestingly you can also use it to add some meta tags,
Safe way to add HTML comment signature at the bottom page.