How to add favicon in WordPress theme and child theme

In this tutorial we will learn about,how to add favicon in WordPress theme and child theme.Favicon is important for branding of the site.Many website and blog are running on WordPress.If you are using a wordpress theme which do not have favicon option,you can add by this method.I used this code in theme which I have created from scratch,in thematic framework and other themes also.

Follow the given below steps to add favicon in wordpress theme

Step 1 : Open WordPress Editor

In Admin panel click on Appearance >> Editor

Step 2: Edit functions.php file

Edit the functions.php file of theme/child theme in wordpress. Paste the given below code in functions.php file

// Custom favicon Function to Include
function customfavicon_link() {
    echo '' . "n";
}
add_action( 'wp_head', 'customfavicon_link' );

Step 3: Upload favicon image

Now upload favicon image in Server at directory/folder where you have installed WordPress.

Step 4:Check favicon in the browser

Now open the web browser and type your wordpress site link. You can see the favicon on top of web browser(tab)

Possible troubleshooting,in case favicon is not visible

The below given are some possibilities because of which you are not able to see favicon on website.All troubleshooting are related to Cache.Hence if you have cache service apart from this, just clear the cache.

(1) Clear the cache of your web browser(user end troubleshooting)
(2) Clear the cache in server if you are using any cacheing server like varnish,nginx etc.
(3) Clear the cache if you are using CDN like cloudflare etc.
(4) If you are using WordPress cache plugin like WP super cache etc. ,clear the cache from it also.
(5) Check the favicon image by typing in browser http://example.com/favicon.ico . Replace example.com with your website url and name of favicon file which you have uploaded.If it is not showing favicon or showing error, it means either there is mistake in functions.php or favicon.ico file is not there/corrupted

3 thoughts on “How to add favicon in WordPress theme and child theme”

  1. This tutorial is very helpful. I had less experience with Favicon. Now I added favicon on my site and working fine. Thank you very much.

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.