https://github.com/soderlind/class-customizer-toggle-control
WordPress Customizer Toggle Control is a generic toggle control you can use to replace the checkbox control.
https://github.com/soderlind/class-customizer-toggle-control
wordpress-customizer-control
Last synced: 6 months ago
JSON representation
WordPress Customizer Toggle Control is a generic toggle control you can use to replace the checkbox control.
- Host: GitHub
- URL: https://github.com/soderlind/class-customizer-toggle-control
- Owner: soderlind
- License: gpl-2.0
- Created: 2016-12-08T00:21:14.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-08-20T10:40:12.000Z (over 6 years ago)
- Last Synced: 2025-08-16T06:58:30.479Z (6 months ago)
- Topics: wordpress-customizer-control
- Language: CSS
- Homepage:
- Size: 175 KB
- Stars: 35
- Watchers: 8
- Forks: 15
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# WordPress Customizer Toggle Control
A generic toggle control you can use to replace the checkbox control.

## Demo
I've added this control to my [customizer demo theme](https://github.com/soderlind/2016-customizer-demo).
## Installing the control
Add the following to your composer.json file and run `composer update`
```javascript
"require": {
"soderlind/class-customizer-toggle-control": "dev-master"
},
"extra": {
"installer-paths": {
"inc/{$name}": [
"soderlind/class-customizer-toggle-control"
]
}
}
```
If you want to install into the `vendor` folder, use
```javascript
"require": {
"soderlind/class-customizer-toggle-control": "dev-master"
},
"extra": {
"installer-paths": {
"vendor/soderlind/{$name}": [
"soderlind/class-customizer-toggle-control"
]
}
}
```
or, clone the repo into `inc`
## Include the class
```php
/**
* Check for WP_Customizer_Control existence before adding custom control because WP_Customize_Control
* is loaded on customizer page only
*
* @see _wp_customize_include()
*/
if ( class_exists( 'WP_Customize_Control' ) ) {
require_once dirname( __FILE__ ) . '/inc/class-customizer-toggle-control/class-customizer-toggle-control.php';
}
```
## Adding the control
```php
$wp_customize->add_control( new Customizer_Toggle_Control( $wp_customize, 'my_control', array(
'label' => esc_html__( 'Toggle me on or off', 'my-lang' ),
'section' => 'my_section',
'settings' => 'my_setting',
'type' => 'ios',// light, ios, flat
) ) );
```
Three different types are available

## Toggling the control title
You must update the [js/customizer-toggle-control.js](js/customizer-toggle-control.js#L10-L15) file if you want to change the title color when a toggle is disabled/enabled.
## Credits
The [CSS](pure-css-toggle-buttons) is copyright (c) 2016 by Mauricio Allende
You can see his [demo at CodePen.io](http://codepen.io/mallendeo/pen/eLIiG)
The CSS is [licensed](https://blog.codepen.io/legal/licensing/) under the terms of the [MIT license](http://opensource.org/licenses/MIT)
## Copyright and License
WordPress Customizer Toggle Control is copyright 2016 Per Soderlind
WordPress Customizer Toggle Control is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.
WordPress Customizer Toggle Control is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with the Extension. If not, see http://www.gnu.org/licenses/.