I want Drupal to look for a favicon in a specific directory dynamically. This is mainly because I'm using the domain access module and I'd like the favicon based off the subdomain that is being used. For example if the url is


I want drupal to look for the favicon in


If the subdomain is example2 I want it to look for the favicon here


I think I have a handle of how to grab the url and base the location on that but right after I have added the favicon, drupal adds it's own. For example I see this in the header

<link rel="shortcut icon" href="sites/all/themes/mytheme/examples2/favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="http://example.url.com/misc/favicon.ico" type="image/vnd.microsoft.icon">

I've accomplished adding my own favicon but it doesn't matter since it is added before anything else. I'm currently using preprocess_html to do this

function mytheme_preprocess_html(&$variables) {
    $favicon = 'sites/all/themes/mytheme/example/favicon.ico';
    $type = 'image/x-icon';
    drupal_add_html_head_link(array('rel' => 'shortcut icon', 'href' => drupal_strip_dangerous_protocols($favicon), 'type' => $type));

(It does not yet have the logic to grab the url) I'm assuming that it is at the top based on the term preprocess. Is there a way to give it weight? Or is there another function I should be using?


I found a solution. in Appearance>Mytheme>Settings, there is an option to uncheck shortcut settings.

After unchecking that option the link provided in mytheme_preprocess_html was able to display the favicon unopposed.

| improve this answer | |

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.