Yanıtlar:
Sen yerleştirebilirsiniz favicon.ico
Temanızın klasöründe (your_theme.info ile aynı seviyede) ve otomatik olarak kullanılacaktır.
Drupal 6, 7 ve 8 için çalışır.
Not: Favicon bazı tarayıcılar tarafından büyük oranda önbelleğe alınır, yenisini görmek için ekstra uzunluklara gitmeniz gerekebilir.
Drupal 8'de, şu settings.yml
konumda bulunan dosyayı kullanabilirsiniz :themes/YOURTHEME/config/install/YOURTHEME.settings.yml
Tema logosu / favicon özelleştirme için bir örnek:
logo:
use_default: false
path: 'themes/YOURTHEME/logo.png'
favicon:
use_default: false
path: 'themes/YOURTHEME/favicon.png'
Ancak, temanız Drupal yönetiminde zaten yüklüyken bu ayarları değiştirirseniz, temanızı kaldırmanız ve yeniden yüklemeniz gerekir. Aksi takdirde, tüm önbellekleri temizleseniz bile, Drupal değişikliklerinizi dikkate almayacaktır.
<?php
function hook_page_alter(&$pages) {
$favicon = "http://example.com/sites/default/files/favicon.ico";
$type = theme_get_setting('favicon_mimetype');
drupal_add_html_head_link(array('rel' => 'shortcut icon', 'href' => drupal_strip_dangerous_protocols($favicon), 'type' => $type));
}
?>
/**
* Implements hook_html_head_alter().
*/
function MYTHEME_html_head_alter(&$head_elements) {
// Remove existing favicon location
global $base_url;
$default_favicon_element = 'drupal_add_html_head_link:shortcut icon:' . $base_url . '/misc/favicon.ico';
unset($head_elements[$default_favicon_element]);
// Specify new favicon location
$element = array(
'rel' => 'shortcut icon',
'href' => '/path-to-favicon/favicon.ico',
);
drupal_add_html_head_link($element);
}
/**
* Implements hook_html_head_alter().
*/
// Remove existing favicon location
function MODULENAME_html_head_alter(&$head_elements) {
global $base_url;
$default_favicon_element = 'drupal_add_html_head_link:shortcut icon:' . $base_url . '/misc/favicon.ico';
unset($head_elements[$default_favicon_element]);
// Specify new favicon location
$element = array(
'rel' => 'shortcut icon',
'href' => '/path-to-favicon/favicon.ico',
);
drupal_add_html_head_link($element);
}
Daha fazla bilgi için hook_html_head_alter sayfasına bakın .
Not: içindeki yeni favicon konumunu listelemeniz gerekmez hook_html_head_alter()
. Genellikle THEMENAME_preprocess_html()
veya ile belirtirim MODULENAME_init()
.
Aşağıdaki kod (özel bir modülde), ek kod eklemek yerine favicon'un yerini alır.
/**
* Implements hook_html_head_alter().
*
* Replaces the favicon.
*
* @param array $head_elements
*/
function MYMODULE_html_head_alter(&$head_elements) {
foreach ($head_elements as $key => $element) {
if (1
// The array key can vary, depending on the original favicon setting.
&& 0 === strpos($key, 'drupal_add_html_head_link:shortcut icon:')
&& !empty($element['#attributes']['href'])
&& 'shortcut icon' === $element['#attributes']['rel']
) {
// Make sure to use a file that actually exists!
$favicon_path = drupal_get_path('module', 'MYMODULE') . '/img/favicon_32.png';
$favicon_url = file_create_url($favicon_path);
// If the favicon path came from a user-provided setting, we would also need drupal_strip_dangerous_protocols().
$element['#attributes']['href'] = $favicon_url;
$element['#attributes']['type'] = 'image/png';
$head_elements[$key] = $element;
}
}
}
Favicon dosya konumu için MYMODULE modül klasörünü veya sites / default / favicon.ico'yu öneririm. Amaç, dosyanın genel dosyalar klasöründe DEĞİL sürüm kontrolünde olmasını sağlamaktır. Web üzerinde yazılabilir olmasını istemiyoruz.
Çoğu insanın * .png yerine * .ico kullanacağını düşünüyorum, bu durumda 'type' orijinal değerini koruyabilir.