Documentazione Novi Hybrid Theme

Font personalizzati

Ho aggiunto una funzionalità nel tema che permette di caricare i font personalizzati, WordPress non permettere il controllo e il caricamento MIME, e io non volevo creare un plugin, quindi ho aggiunto questa funzionalità.

Per poter usufruirne devi seguire questi passaggi:

Aggiungi questo codide alla functions.php del tema child

//!------------------------
//!------- CONTROLLO E CARICAMENTO MIME
//!------------------------
add_filter('wp_check_filetype_and_ext', function ($data, $file, $filename, $mimes) {
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$valid_exts = ['ttf', 'otf', 'woff', 'woff2'];

if (in_array(strtolower($ext), $valid_exts)) {
$data['ext'] = $ext;
$data['type'] = $mimes[$ext] ?? 'application/octet-stream';
}

return $data;
}, 10, 4);

add_filter('upload_mimes', function ($mimes) {
if (!current_user_can('manage_options')) {
return $mimes;
}

return array_merge($mimes, [
'ttf' => 'font/ttf',
'otf' => 'font/otf',
'woff' => 'font/woff',
'woff2' => 'font/woff2',
]);
});