How to add favicon by Function

If you want to create a clear WordPress theme/template then it’s very import to optimize code and function. so if you use favicon for your site by function.php it’s will optimize your site greatly. To do so, Simply copy and paste the following code to your theme’s functions.php:

function my_theme_add_favicon(){ ?>
 <link rel="shortcut icon" href="/img/favicon.ico"/>
 <?php }

** Make sure to replace href attribute to point to your favicon file properly.

if you face any problem please let me know by comment