Problem with favicon in the latest wp

Im having a problem with the favicon icon in WordPress 5.4.2. Im including my own favicon in the sites header.php, that is used for wp and wp non related static pages. The problem is that when I open a pdf file inside this site, the wp logo automatically appears as a favicon, instead of my site's icon. This would not happen in previous wp versions. Is there a way to change the wp icon to my sites icon, or just to nothing?

Topic favicon Wordpress

Category Web


The reason for this is because you didn't use the WP site icon API to set your icon.

When no favicon tag is possible, the browser will fall back to a URL such as yoursite.com/favicon.png. This gets picked up by WP which then displays the sites current icon. If none is set, a WP logo is used. That is why your PDF file gets a WP logo.

You have several options available:

  • Use the theme customizer to set the sites icon
  • Upload a favicon.png and favicon.ico to the root of your site
  • Use the site_icon_meta_tags filter to adjust the header meta tags
  • Use the get_site_icon_url filter to override the URL of the image for a given size

Generally I would advise relying on the WP site icon mechanism rather than adding HTML tags to the header, as it also accounts for various sizes that OS' might request, such as app icons in iOS


There is basic Favicon functionality built into WP. Go to Theme Customiser > Site Identity and use the 'Site Icon'.

In some cases its better to have custom code in the head, and the above doesn't work for non WP pages within the site, if thats what you are using. However its worth a try if you hadn't already.

In the past I have also used a website that generates real favicon code for the head, including a variety of sizes and allows you control the look of favicons on smartphones etc. So going with a more detailed setup in the head may also be worth exploring?

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.