do_action( 'wp_head' )
Prints scripts or data in the head tag on the front end.
Description Description
Source Source
Changelog Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
taken from the old codex pages:
function hook_css() { ?> <style> .wp_head_example { background-color : #f1f1f1; } </style> <?php } add_action('wp_head', 'hook_css');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 hool do_action(‘wp_head’). WordPress core files then hooks it multiple times to print the head,
Expand full source codeCollapse full source code
However, more interestingly you can also use it to add some meta tags,
function hook_nocache() { ?> <meta http-equiv="cache-control" content="max-age=0" /> <meta http-equiv="cache-control" content="no-cache" /> <meta http-equiv="expires" content="0" /> <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" /> <meta http-equiv="pragma" content="no-cache" /> <?php } add_action('wp_head', 'hook_nocache');