Search code examples
redminefavicon

Add a favicon to redmine theme


redmine uses the favicon placed at /usr/share/redmine/public/favicon.ico

I found a lot of code snippets using cd /usr/share/redmine/; grep -HR favicon app/

app/helpers/application_helper.rb:  def favicon
app/helpers/application_helper.rb:    "<link rel='shortcut icon' href='#{favicon_path}' />".html_safe
app/helpers/application_helper.rb:  # Returns the path to the favicon
app/helpers/application_helper.rb:  def favicon_path
app/helpers/application_helper.rb:    icon = (current_theme && current_theme.favicon?) ? current_theme.favicon_path : '/favicon.ico'
app/helpers/application_helper.rb:  # Returns the full URL to the favicon
app/helpers/application_helper.rb:  def favicon_url
app/helpers/application_helper.rb:    path = favicon_path
app/views/journals/index.builder:  xml.icon    favicon_url
app/views/common/feed.atom.builder:  xml.icon    favicon_url
app/views/layouts/base.html.erb:<%= favicon %>

But no luck finding more info about how to set the favicon_path or favicon_url.

Workaround:

I added a small javascript in the theme folder: javascripts/theme.js:

document.head = document.head || document.getElementsByTagName('head')[0];

function changeFavicon(src) {
 var link = document.createElement('link'),
     oldLink = document.getElementById('dynamic-favicon');
 link.id = 'dynamic-favicon';
 link.rel = 'shortcut icon';
 link.href = src;
 if (oldLink) {
  document.head.removeChild(oldLink);
 }
 document.head.appendChild(link);
}

changeFavicon('../themes/freifunk-red-andy/images/favicon.ico');

(But that workaround only works if the visitor uses javascript)


Solution

  • Redmine automatically loads the first file it finds inside the favicon sub-directory of your theme. Thus, if you put your favicon into e.g. favicon/favicon.ico, it will be automatically used by Redmine.