Free Consultation

Wordpress wp_head & wp_footer functions

Wordpress Logo

Two key things to add to a Wordpress theme are the wp_head and wp_footer functions. These two functions are known as “action hooks”. Depending on how much you know about theme development, action hooks may be easy or difficult to understand. Action hooks are placeholders where code is dynamically added to a theme.

What this means is that the wp_head and wp_footer functions act as placeholders for plugins to insert code to the <head> and <footer> of the theme respectively. For example, if you have a Google Analytics plugin installed on your Wordpress website, the plugin uses wp_head to add some javascript to the <head> of your website in order for Google Analytics to track visits. Without this code the plugin would not be able to add the code to your theme.

How to add wp_head to a Wordpress theme

To add the wp_head function correctly to your Wordpress theme, simply open your theme’s header.php file and add the following line of PHP code right before the closing head tag (</head>):

<?php wp_head(); ?>

How to add wp_footer to a Wordpress theme

To correctly add the wp_footer function to your Wordpress theme, open the theme’s footer.php file and add the following line of PHP code before the closing </body> tag:

<?php wp_footer(); ?>

Broken Plugins

You may find that a Wordpress plugin isn’t working on your website. Maybe the plugin worked at one point, but then you updated either the plugin or Wordpress and it stopped working. Maybe the plugin never worked at all. If you do find that you are having trouble with a plugin, your first step should be to make sure that you have wp_head and wp_footer correctly placed in your template.

Conclusion

Action hooks like wp_head and wp_footer are essential to how plugins interact with your Wordpress theme. In the past these funtions were not always needed, so if you have a theme that hasn’t been updated in a while, it would be a good idea to add these action hooks to protect your theme from some future problems.

Lead Generating Websites Starting At $150/month

Questions? Let's talk and see if I'm a good fit for your business.

(Expect a fast reply 😁)