0

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?

5
  • When you say you're adding the favicon, how? Are you manually adding the html tag? Or are you using the WordPress provided API to do it? If your theme supports site icons then the site icon is repurposed for the favicon if the API doesn't enforce a specific icon. There's also the rewrite rules, but you should confirm what you meant by adding the favicon before going down that path
    – Tom J Nowell
    Commented Aug 5, 2020 at 9:48
  • Im adding it manually in my head. Commented Aug 5, 2020 at 9:56
  • Just to be unambiguous, you mean you're adding the HTML tag manually in your head? Or you're calling the favicon API manually instead of via wp_head? Note that there is no code in your question that would clear this up so you have to be specific as it makes a big difference to what the answer will be
    – Tom J Nowell
    Commented Aug 5, 2020 at 9:58
  • I am adding it manually in a file separated from wordpress. I just added the icon using Theme Customiser and it solved the problem. Thanks for the feedback. Commented Aug 5, 2020 at 10:04
  • So you specifically added the HTML tag? I asked because there is more than 1 way to add it manually, but it wasn't clear what you meant. Now that I know you meant you added the HTML tag for favicons manually I can write an appropriate answer
    – Tom J Nowell
    Commented Aug 5, 2020 at 10:08

3 Answers 3

1

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?

2

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

1
  • 1
    This is a far more detailed answer than mine , Tom. Thanks.
    – t2pe
    Commented Aug 5, 2020 at 10:18
0

In one particular site the core redirect from /favicon.ico didn't work because there were no rewrite rules in the options. Flushing the rewrite rules alone also didn't work - for some reason the permalink options weren't correctly set. I had to set these in permalinks settings again and then the /favicon.ico redirect started working correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.