What is the use of the wp_head() function in WordPress?

wp_head() is a function that fires the wp_head action. It is called in header.php just before </head>. Plugins and WordPress use that hook to print things in the head: enqueued styles and scripts, meta tags, the canonical link, the RSS links and SEO data.

Without wp_head() many plugins and the styles you enqueue will not load. Its partner is wp_footer(), which must be before the closing </body> tag.

<?php
add_action( 'wp_head', function () {
	echo '<meta name="author" content="Tutorials Class">' . "\n";
} );
Terminal output

$ curl -s http://example.com/ | grep 'name="author"'
<meta name="author" content="Tutorials Class">


Learn more about the similar topics:
Tutorials
WordPress Themes
WordPress Top Theme List
WordPress Theme Files and Functions
WordPress Template Hierarchy
WordPress Enqueue Scripts and Styles
WordPress Loop
WordPress WP_Query Class
Exercises & Assignments
Build and activate a minimal classic theme
Show the three latest posts with WP_Query
Load a stylesheet with wp_enqueue_style and a version
Show a message only on the front page
Create a child theme which changes the footer
Interview Questions & Answers
What is a WordPress theme?
What are commonly used WordPress theme functions?
Which function is used to get the home URL in WordPress?
Which are the necessary files for a WordPress theme?
What is the use of the wp_head() function in WordPress?
What is the WordPress Loop?
What is the difference between is_home() and is_front_page()?