X

Insert Favicon with Function

Snippets by IsItWP

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.

Comments   Leave a Reply

  1. Thank you very much for this useful snippet!

    1. Hey glad it helped. 🙂

  2. 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

  3. 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

  4. Ismail Fahmi May 5, 2020 at 1:57 am

    It works, Men…
    Thank u very much for sharing this!

    1. Shahzad Saeed May 5, 2020 at 7:23 am

      Glad it helped, Ismail

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!