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.

One 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:
    include(TEMPLATEPATH."/includes/post.footer.info.php");

    This constant will point to the stylesheet directory when the theme is child theme
    include(STYLESHEETPATH."/main.flow.blogg.php");

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>