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.

As a freelance musician and teacher my website is very important for generating business and maintaining good contact with my clients. I have found Jo Cox Design very useful to help maintain elements of my site which are more complex. I like to have control of my site but I often find there are things I cannot achieve on my own. I would certainly recommend Jo as a friendly person who’s easy to work with and who can help you achieve such goals.

Trev Williams