Loading...

bs Dark Mode

| 45 Comments on bs Dark Mode

Enable Bootstrap dark mode effortlessly with this plugin. Visitors can toggle between light and dark modes for a comfortable viewing experience.

Installation

  1. Buy plugin
  2. In your admin panel, go to Plugins > and click the Add New button.
  3. Click Upload Plugin and Choose File, then select the Plugin’s .zip file. Click Install Now.
  4. Click Activate to use your new Plugin right away.

Shortcodes

If the plugin is installed and activated, dark mode is already active and follows the OS settings. Additionally, there are two templates available that allow visitors to overwrite the OS settings using a switch/dropdown via shortcode in a widget position.

Switch template

Click me!

To enable the Switch template, use the

[bs-dark-mode]

shortcode on any widget position where you want to show the switch. The plugin will automatically detect the OS’s dark/light theme and switch accordingly when the user clicks on the switch.

Wrap shortcode in a div with Bootstrap font-size classes to adjust the size:

<div class="fs-1">
  [bs-dark-mode]
</div>

To enable the Dropdown template, use the

[bs-dark-mode-dropdown]

shortcode on any widget position where you want to show the dropdown toggler. The dropdown has options for light, dark, and auto mode.

Filters

Use filters to change classes, texts and icons in child-theme’s functions.php:

/**
 * Change dark mode btn class
 */
function dark_mode_button_class() {
  return "btn btn-light";
}
add_filter('bootscore/class/dark-mode/dropdown/button', 'dark_mode_button_class', 10, 2);
/**
 * Remove dropdown button text `visually-hidden` class
 */
function dark_mode_dropdown_button_text_class() {
  return "";
}
add_filter('bootscore/class/dark-mode/dropdown/button/text', 'dark_mode_dropdown_button_text_class', 10, 2);
/**
 * Change dropdown button text
 */
function dark_mode_dropdown_button_text() {
  return "My text";
}
add_filter('bootscore/dark-mode/dropdown/button/text', 'dark_mode_dropdown_button_text', 10, 2);
/**
 * Change dark-mode dropdown-menu class
 */
function change_dark_mode_dropdown_menu_class() {
  return 'dropdown-menu-end shadow';
}
add_filter('bootscore/class/dark-mode/dropdown/menu', 'change_dark_mode_dropdown_menu_class');
/**
 * Change dark-mode sun icon
 */
function change_dark_mode_sun_icon() {
  return '<i class="fa-solid fa-lightbulb"></i>';
}
add_filter('bootscore/icon/sun', 'change_dark_mode_sun_icon');
/**
 * Change dark-mode moon icon
 */
function change_dark_mode_moon_icon() {
  return '<i class="fa-solid fa-cloud-moon"></i>';
}
add_filter('bootscore/icon/moon', 'change_dark_mode_moon_icon');
/**
 * Change dark-mode auto icon
 */
function change_dark_mode_auto_icon() {
  return '<i class="fa-solid fa-star-half-stroke"></i>';
}
add_filter('bootscore/icon/circle-half-stroke', 'change_dark_mode_auto_icon');
/**
 * Change dark-mode dropdown-item description class
 */
function change_dark_mode_dropdown_description_class() {
  return 'text-danger bg-success';
}
add_filter('bootscore/class/dark-mode/dropdown/item/description', 'change_dark_mode_dropdown_description_class');

Overriding templates via theme

Template files can be found within the /bs-dark-mode/templates/ plugin directory.

Edit files in an upgrade-safe way using overrides. Copy the template into a directory within your theme named bs-dark-mode keeping the same file structure but removing the templates subdirectory. Path must be your-theme/bs-dark-mode/[file].php.

The copied file will now override the bs Dark Mode template file. Change HTML as you want.

Templates that can be overridden

  • sc-switch.php
  • sc-dropdown.php

Custom HTML togglers

Instead of using predefined shortcode togglers, the plugin also supports custom HTML togglers such as checkboxes, radios and button groups.

Checkbox

Provide visitors with a simple choice between the light and dark themes with a checkbox:

<div class="dark-mode-switch form-check">
  <label class="form-check-label">
    <input class="bs-theme-switcher form-check-input" type="checkbox">
    Dark theme?
  </label>
</div>

Checkbox with button

Using the checkbox toggle button.

<div class="dark-mode-switch mb-3">
  <label class="btn btn-primary">
    <input class="bs-theme-switcher btn-check" type="checkbox">
    <span class="d-td-none"><i class="fa-solid fa-sun"></i></span><span class="d-tl-none"><i class="fa-solid fa-moon"></i></span>
  </label>
</div>

Radios

Option to set the theme to “auto” using radios:

<div class="dark-mode-radio">
  <div class="form-check">
    <label class="form-check-label">
      <input class="form-check-input" type="radio" name="theme-radio" data-bs-theme-value="light">
      Light
    </label>
  </div>
  <div class="form-check">
    <label class="form-check-label">
      <input class="form-check-input" type="radio" name="theme-radio" data-bs-theme-value="dark">
      Dark
    </label>
  </div>
  <div class="form-check">
    <label class="form-check-label">
      <input class="form-check-input" type="radio" name="theme-radio" data-bs-theme-value="auto">
      Let the system decide that
    </label>
  </div>
</div>

Buttons

Buttons with icons in a btn-group:

<div class="dark-mode-btn btn-group" role="group" aria-label="Basic example">
  <button type="button" class="btn btn-outline-primary" data-bs-theme-value="auto">
    <i class="fa-solid fa-display"></i>
  </button>
  <button type="button" class="btn btn-outline-primary" data-bs-theme-value="light">
    <i class="fa-solid fa-sun"></i>
  </button>
  <button type="button" class="btn btn-outline-primary" data-bs-theme-value="dark">
    <i class="fa-solid fa-moon"></i>
  </button>
</div>

The logo isn’t part of Bootstrap’s dark mode because it depends on the type of logo being used. Bootscore/Child have 2 logos stored in folder /assets/img/logo/:

  • logo.svg is the default logo and displayed if data-bs-theme is set to light and auto as well.
  • logo-theme-dark.svg is displayed if data-bs-theme is set to dark.

Replace them with your own svg images.

Changelog

Currently bs Dark Mode v6.1.0

A detailed changelog can be found in the plugin’s readme.txt file. It can also be accessed in the WordPress backend by navigating to Plugins > bs Dark Mode > View details > Changelog tab.