How to add a favicon to your WordPress site

If you want, you can easily add a favicon to you WordPress site. Either you download a plugin to help you with this or you can simply add this code to your themes functions.php.

function favicon() {
echo '<link rel="shortcut icon" type="image/x-icon" href="'.get_bloginfo( 'stylesheet_directory' ).'/images/favicon.ico">';
add_action('wp_head', 'favicon');

As you can see there is a directory called “images” where I put the favicon image. You can of course change this to make is suit your theme.

One other thing worth mentioning is that I use get_bloginfo( ‘stylesheet_directory’ ) instead of get_bloginfo( ‘template_url’ ) which makes this code also functional for child themes. The reason for not using get_bloginfo( ‘template_url’ ) is that it always returns the parent theme directory.

About Fredrik Malmgren

Fredrik Malmgren is an entrepreneur, project manager and developer specialized in WordPress. Read more about me or get in contact with me. You can also find me on Twitter. (@fredrikmalmgren).
This entry was posted in Tutorials, WordPress and tagged , , , . Bookmark the permalink.

1 Response to How to add a favicon to your WordPress site

  1. krillo says:

    Yes the get_bloginfo( ‘template_url’ ) will allways point to parent theme directory. As will this constant:

    This constant will point to the stylesheet directory when the theme is child theme

Leave a Reply to krillo Cancel reply

Your email address will not be published. Required fields are marked *