Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

what about if you are on a multi site install, where would you put the favicon to have it automaticallly recognized by the browser (and no blot the code with link tag)cause there is no real root per se?

Thank you in advance for your help on this

share|improve this question
    
    
Thank you for the link, but the very reason of this post is because I previously posted my question on this thread but it has been deleted because it was off topi –  Steffy Kristiensen Jan 14 '12 at 19:20
    
Just drop it in the same folder as WordPress - that's your root (unless you've got it installed in a subfolder). –  TheDeadMedic Jan 14 '12 at 19:53
    
@theDeadedic thank you for your answer, but in a context of multi site install, what would be considered as root. let say that I have 10 sites under the network belt, where would you put those 10 different favicon? –  Steffy Kristiensen Jan 15 '12 at 5:31
    
So, just to be clear, each site has a different favicon? –  TheDeadMedic Jan 15 '12 at 11:15
show 1 more comment

2 Answers

I would use a rewrite to map requests for /favicon.ico to /icons/example.com.ico:

RewriteCond %{REQUEST_URI} ^/favicon\.ico
RewriteCond %{SERVER_NAME} ^(www\.)?([a-z0-9]+)
RewriteCond %{DOCUMENT_ROOT}/icons/%2.ico -f
RewriteRule . /icons/%2.ico [L]

Note the regex for line #2 depends on your set-up - is each website its own domain, or a subdomain/subdirectory of a primary domain?

I would also place a default favicon in the root, which will get pulled if no favicon exists in /icons for the current site.

share|improve this answer
add comment

Another approach is to print the links in the <head>.
The only caveat is that the following is not working in Sub-directory installs, only in Sub-domain.
Somehow get_current_blog_id is only returns the ID 1 in when define('SUBDOMAIN_INSTALL', false);.

<?php
/**
 * Plugin Name: Multisite Favicons
 * Description: Favicons should be stored in http://example.com/icons/domain_name.ico | If the site is subsite.example.com, the favicon should be subsite.ico
 **/

add_filter( 'wp_head', 'multisite_favicons_wpse_38903' );

function multisite_favicons_wpse_38903()
{ 
    // This function returns true if not Multisite
    if( is_main_site() ) 
        return;

    global $current_site;

    $details = get_blog_details( get_current_blog_id() );
    $blogname = 
        ( is_subdomain_install() ) 
        ? str_replace( '.' . $current_site->domain, '', $details->domain ) 
        : $details->path;

    printf(
        "<link rel='shortcut icon' href='%s/icons/%s.ico' type='image/x-icon'/>\n", 
        site_url(),
        $blogname
    );
}

Interesting blog post: Everything You Ever Wanted to Know about Favicons

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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