feat(customizer): integrasi pengaturan font dinamis dan color scheme picker
This commit is contained in:
+51
-9
@@ -20,22 +20,64 @@ add_action( 'after_setup_theme', 'edukarsa_setup' );
|
||||
|
||||
// 2. MENGHUBUNGKAN ASET (CSS & JS FRONTEND)
|
||||
function edukarsa_scripts() {
|
||||
// Memuat Google Font: Plus Jakarta Sans (Native Webfont)
|
||||
wp_enqueue_style(
|
||||
'edukarsa-google-fonts',
|
||||
'https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap',
|
||||
array(),
|
||||
null
|
||||
);
|
||||
$font_choice = get_option( 'edukarsa_font_choice', 'plus_jakarta_sans' );
|
||||
$font_url = '';
|
||||
$font_family = "'Plus Jakarta Sans', system-ui, sans-serif";
|
||||
|
||||
// CSS Utama Tema dengan Cache Busting time()
|
||||
switch ( $font_choice ) {
|
||||
case 'inter':
|
||||
$font_url = 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap';
|
||||
$font_family = "'Inter', system-ui, sans-serif";
|
||||
break;
|
||||
case 'poppins':
|
||||
$font_url = 'https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700;800&display=swap';
|
||||
$font_family = "'Poppins', system-ui, sans-serif";
|
||||
break;
|
||||
case 'roboto':
|
||||
$font_url = 'https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700;900&display=swap';
|
||||
$font_family = "'Roboto', system-ui, sans-serif";
|
||||
break;
|
||||
case 'system':
|
||||
$font_url = '';
|
||||
$font_family = "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif";
|
||||
break;
|
||||
case 'plus_jakarta_sans':
|
||||
default:
|
||||
$font_url = 'https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap';
|
||||
$font_family = "'Plus Jakarta Sans', system-ui, sans-serif";
|
||||
break;
|
||||
}
|
||||
|
||||
$deps = array();
|
||||
if ( ! empty( $font_url ) ) {
|
||||
wp_enqueue_style( 'edukarsa-dynamic-font', $font_url, array(), null );
|
||||
$deps[] = 'edukarsa-dynamic-font';
|
||||
}
|
||||
|
||||
// Load file style.css utama
|
||||
wp_enqueue_style(
|
||||
'edukarsa-style',
|
||||
get_template_directory_uri() . '/style.css',
|
||||
array('edukarsa-google-fonts'),
|
||||
$deps,
|
||||
time(),
|
||||
'all'
|
||||
);
|
||||
|
||||
// Ambil opsi skema warna dari database
|
||||
$primary_color = sanitize_hex_color( get_option( 'edukarsa_primary_color', '#0b4a8e' ) );
|
||||
$secondary_color = sanitize_hex_color( get_option( 'edukarsa_secondary_color', '#1a73e8' ) );
|
||||
$heading_color = sanitize_hex_color( get_option( 'edukarsa_heading_color', '#0f172a' ) );
|
||||
|
||||
// Injeksi CSS variables dinamis langsung ke selector :root
|
||||
$custom_css = "
|
||||
:root {
|
||||
--primary-color: {$primary_color};
|
||||
--secondary-color: {$secondary_color};
|
||||
--heading-color: {$heading_color};
|
||||
--font-main: {$font_family};
|
||||
}
|
||||
";
|
||||
wp_add_inline_style( 'edukarsa-style', $custom_css );
|
||||
}
|
||||
add_action( 'wp_enqueue_scripts', 'edukarsa_scripts' );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user