Set Site Icon programmatically (eg. using `wp cli`)

The ‘official rules’ about site icons are here:https://www.w3.org/TR/html5/links.html#link-type-icon .

They provide this example of site icons for several sizes:

<link rel=icon href=favicon.png sizes="16x16" type="image/png">
  <link rel=icon href=windows.ico sizes="32x32 48x48" type="image/vnd.microsoft.icon">
  <link rel=icon href=mac.icns sizes="128x128 512x512 8192x8192 32768x32768">
  <link rel=icon href=iphone.png sizes="57x57" type="image/png">
  <link rel=icon href=gnome.svg sizes="any" type="image/svg+xml">

The above link also specifies if the ‘link rel=icon …’ is not specified, then the /favicon.ico file (in the site root) will be used.

It further states:

“If multiple icons are provided, the user agent must select the most
appropriate icon according to the type, media, and sizes attributes.”

(“User agent” is the browser rendering the site.)

Also, see one of the answers here https://stackoverflow.com/questions/9943771/adding-a-favicon-to-a-static-html-page that references an application to create all of the different icon sizes and the code needed to use them:

Actually, to make your favicon work in all browsers, you must have
more than 10 images in the correct sizes and formats.

I created an App (faviconit.com) so people don´t have to create all
these images and the correct tags by hand.

I have not tried the application referenced. YMMV.

And, this question/answer might also be helpful: https://stackoverflow.com/questions/53464667/best-practice-for-ordering-icon-link-tags-in-html-head .