Wordpress Snippets

Add A Favicon To Your WordPress Website

Favicons, short for favorite icons, are a small but significant part of branding a website. They are used to display a 16×16 or 32×32 pixel image before the page title in your browser window. Favicons are also used for bookmarks in browsers and touchscreen devices. Favicons not only make your blog look more professional, but they also make it easier for people to find it in their long lists of bookmarks and favorites. Anyone can create a favicon and add it to their third-party hosted WordPress blog or website. It’s extremely very simple.

Fortunately, installing a favicon on your WordPress site is a piece of cake. And although there are plugins available that can do it for you, such a task definitely falls into the “you absolutely do not need to use a plugin for this” category. After all, you want to keep your site lean and mean.

Simply upload your favicon to website root folder and paste this code snippet in your functions.php file.

// add a favicon to your wordpress website
function wcs_add_favicon() {
    echo '<link rel="icon" type="image/x-icon" href="' . esc_url( home_url( '/' ) ) . 'favicon.ico" />';
}
add_action( 'wp_head', 'wcs_add_favicon' );

If you have uploaded your favicon in your theme image folder then you can use this code snippet.

// add a favicon to your wordpress website
function wcs_add_favicon() {
    echo '<link rel="icon" type="image/x-icon" href="' . get_template_directory_uri() . '/favicon.ico" />';
}
add_action( 'wp_head', 'wcs_add_favicon' );

I would recommend uploading favicon in root folder because many browser and services simply check favicons at website root. And if they do not find it there, they return 404 error.

Hire Us. Or just say Hi!
Need a job? Apply to get one.