WordPress themes should possess a number of different hooks by default, allowing active plugins to alter or add output when pages are rendered. WordPress development guidelines specify the names and locations of the expected WordPress hooks in themes.
There are three WordPress hooks that you need to add to almost every custom theme. They are:
First, add the wp_head
hook. Find the end tag of the HTML head
element (</head>, often in header.php)
and place your cursor on the line before it. Insert the following:
<?php do_action( 'wp_head' ); ?>
Next, add the wp_footer
hook. Find the end tag of the HTML body
element (</body>, often in footer.php)
and place your cursor on the line before it. Insert the following:
<?php do_action( 'wp_footer' ); ?>
Finally, insert the comment_form
hook. Locate the end tag of the HTML form
element for the comment form (</form>, often in comments.php
and comments-popup.php)
and place your cursor on the line before it. Insert the following:
<?php do_action( 'comment_form', $post->ID ); ?>
If you are using the default comments form layout, you won't have to explicitly add the comment_form
hook because it is provided in the default theme's comments.php
file.
Plugins use these hooks to add to or modify the rendered output of a theme's template files. Often the modification includes linking to or outputting JavaScript, CSS, or HTML code. Many popular plugins use the above hooks, and making sure that they are present is essential to the plugin's proper operation.