3

I have uploaded some PDFs to the Media Library.

I cannot find a way to set the browser favicon for the PDF media files.

Where does WordPress get the favicon from?

Is there anyway to control the PDF Media file favicon?

  • There should not be a favicon for a PDF file, a favicon is generaly for the whole site. If you mean something else please explain. – Mark Kaplun Sep 29 '15 at 16:36
  • Ah, but there is in Google Chrome. Explanation: the "favicon" is the 16x16 graphic image that appears in the browser title tab. – tammy Sep 29 '15 at 16:52
  • so if you write an html page, host your PDF on some non wordpress server, what do you need to do to set a specific favicon for a PDF which is different then the sites favicon? – Mark Kaplun Sep 29 '15 at 17:12
  • 1
    what I see is a site favicon and you don't even need to do anything as controlling it is part of version 4.3 – Mark Kaplun Sep 29 '15 at 18:06
  • 1
    it is the "site icon" under "site identity" in the cusromizer – Mark Kaplun Sep 29 '15 at 18:36
1

To summarize the discussion in the comments, the answer for the question as it is asked is that it is not possible. The web standards as they are right now do not have a facility to declare a favicon for PDF files, only for the whole domain via the favicon.ico file.

You can try to hack around it by

  1. set the favicon.ico at the root of the site to the icon you want to be associated with media files and use the wordpress 4.3 site icon feature to handle the icon for the html (which should have priority over the favicon.ico).

  2. server the media files from a different domain (for example a subdomain of the main site) and set there a favicon.ico that you want to be associated with the media files.

2

Well, I think you only need to modify the favicon.ico file in your WordPress root directory.

Previous answer:

I guess you want to change this icon (/wp-includes/images/media/document.png):

icon

that shows up for PDF documents in the Media Library.

You could then use the wp_mime_type_icon filter to change the icon:

add_filter( 'wp_mime_type_icon', function( $icon, $mime, $post_id )
{
    if( 'application/pdf' === $mime && $post_id > 0 )
        $icon = 'http://example.tld/pdf.png'; // Modify this to your needs!

    return $icon;
}, 10, 3 ); 

But for favicons, you can check out my answer here.

  • No, that's not the favicon that appears in the browser for me @birgire. See my most recent comment back to MarkKaplun above. – tammy Sep 29 '15 at 17:32
  • I just updated the answer, after reading your comment, please add all relevant info into the question itself, thanks @tammy – birgire Sep 29 '15 at 17:33
  • Ah, good tip @birgire, I'll check into that and post back. – tammy Sep 29 '15 at 17:34
  • Yes, it looks like that is what's happening. Do you know if there is any "clever" way of overriding that? The reason is that the site that shows the "wrong" desired-favicon is only one site in the many multisite networks I am running. So I do not want to alter the base favicon. I merely want to set a favicon for this particular MS network site. Is that do-able @birgire? – tammy Sep 29 '15 at 17:38
  • 1
    setting favicon is actually a feature of 4.3 and should work on all types of servers – Mark Kaplun Sep 29 '15 at 18:07
0

If you're getting a conflict between your WP site having one favicon and your uploads folder having another, check that you don't have an older favicon.ico lingering in your root directory while your new one was added via the WP site admin. Just encountered this on a site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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