diff --git a/functions.php b/functions.php
index f10dd73..695205d 100644
--- a/functions.php
+++ b/functions.php
@@ -208,6 +208,32 @@ if ( ! function_exists( 'boxstyle_styles' ) ) {
add_action( 'wp_enqueue_scripts', 'boxstyle_styles' );
+/* Light & dark mode switch
+/* ------------------------------------ */
+function boxstyle_switch() {
+
+ if ( get_theme_mod('light-dark-switch','off') =='on' ) {
+
+ $current_mode = 'light';
+ if ( isset( $_COOKIE['theme_mode'] ) && ! empty( $_COOKIE['theme_mode'] ) ) {
+ $current_mode = $_COOKIE['theme_mode'];
+ }
+ if ( in_array( $current_mode, array( 'light', 'dark' ) ) ) {
+ wp_enqueue_style( 'boxstyle-scheme', get_template_directory_uri() . '/' . esc_attr( $current_mode ) . '.css' );
+ }
+ wp_enqueue_script( 'boxstyle-cookie', get_template_directory_uri() . '/js/cookie.min.js', array(), '2.2.0', true );
+ wp_enqueue_script( 'boxstyle-switch', get_template_directory_uri() . '/js/switch.js', array( 'jquery' ), '2.0', true );
+ $data = array(
+ 'template_directory_uri' => get_template_directory_uri(),
+ 'stylesheet_directory_uri' => get_stylesheet_directory_uri(),
+ );
+ wp_localize_script( 'boxstyle-switch', 'boxstyleObject', $data );
+
+ }
+}
+add_action( 'wp_enqueue_scripts', 'boxstyle_switch' );
+
+
/* ------------------------------------------------------------------------- *
* Template functions
/* ------------------------------------------------------------------------- */
diff --git a/functions/theme-options.php b/functions/theme-options.php
index d516633..c30e86c 100644
--- a/functions/theme-options.php
+++ b/functions/theme-options.php
@@ -610,6 +610,15 @@ Kirki::add_field( 'boxstyle_theme', array(
'section' => 'styling',
'default' => 'on',
) );
+// Styling: Switch
+Kirki::add_field( 'boxstyle_theme', array(
+ 'type' => 'switch',
+ 'settings' => 'light-dark-switch',
+ 'label' => esc_html__( 'Light/Dark Theme Switch', 'boxstyle' ),
+ 'description' => esc_html__( 'Do not use with Dark Theme option enabled', 'boxstyle' ),
+ 'section' => 'styling',
+ 'default' => 'off',
+) );
// Styling: Dark
Kirki::add_field( 'boxstyle_theme', array(
'type' => 'switch',
diff --git a/header.php b/header.php
index c12660c..d35bf3a 100644
--- a/header.php
+++ b/header.php
@@ -17,7 +17,7 @@