How to: Add to wp_head From functions.php

11th October 2013

If you’re looking to add elements such as favicons and tracking codes to <head>, the best way forward is to put them together in your functions.php file and then pull through using the wp_head hook. To do this, open up your functions.php and create a new function. It should go something like this (I’ve used the favicon example):

Once you’ve created the function, your next task is to use wp_head to hook it in to the of your theme. To do that, you’re going to need add_action:

Put the two together and you’ll see that your favicon script is loaded just where it needs to be – at the end of your theme .

This method works for all sorts, including pulling through customisable elements from a theme options page like custom colours, typography and tracking codes.

NB: Because this post is more than two years old, and the world of web design and technology moves on so quickly, the information in it may now be out of date


Leave a Reply

We couldn’t believe our luck when Jo offered to build us our website for free. We were even more astounded when only weeks later we had a great site, purpose build to our needs. We couldn’t have paid for a better site or more fluid an experience of commissioning a website.

Emma Gordon (Centre Manager, Bicester Green)