Are you looking for a way to add a favicon from the functions.php file using HTML? While there’s probably a plugin for this, we have created a quick code snippet that you can use to insert favicon with function in WordPress.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
function myfavicon() { echo '<link rel="Shortcut Icon" type="image/x-icon" href="'.get_bloginfo('wpurl').'/favicon.ico" />'; } add_action('wp_head', 'myfavicon');
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 9 best WordPress events plugins and 15 best content marketing tools.
Thank you very much for this useful snippet!
Hey glad it helped. 🙂
Hi,
This worked perfectly as using the new WordPress theme editor and there is no way to add an icon without a site image. Thanks
Already have links to favicon on different size, however I just wanted to add rel=”Shortcut Icon” type=”image/x-icon” on exsisting link.
Also do you know how to preload favicon icon
It works, Men…
Thank u very much for sharing this!
Glad it helped, Ismail