helgatheviking / kia-customizer-toggle-control
A Toggle Control for the WordPress Customizer.
Installs: 243
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 1
Type:wordpress-dropin
Requires
- php: >=7.4
- composer/installers: ~2.0
Requires (Dev)
README
A toggle control for the WordPress Customizer
Installation
Add the following to your composer.json
file and run composer update
"repositories": [
{
"type": "git",
"url": "https://github.com/helgatheviking/kia-customizer-toggle-control.git"
}
],
"require": {
"helgatheviking/kia-customizer-toggle-control": "dev-main"
},
"extra": {
"installer-paths": {
"includes/{$name}": [
"helgatheviking/kia-customizer-toggle-control"
]
}
Adding the control
/** * Add range slider to Customizer. * * @param obj $wp_customize */ function kia_customizer( $wp_customize ) { // Include the class require_once dirname( __FILE__ ) . '/includes/kia-customizer-toggle-control/class-kia-customizer-toggle-control.php'; // Register the control types that we're using as JavaScript controls. $wp_customize->register_control_type( 'KIA_Customizer_Toggle_Control' ); $wp_customize->add_setting( 'my_setting', array( 'default' => false, 'type' => 'option', 'capability' => 'edit_themes', 'transport' => 'postMessage', 'sanitize_callback' => array( 'KIA_Customizer_Radio_Image_Control', 'sanitize' ), 'sanitize_js_callback' => array( 'KIA_Customizer_Radio_Image_Control', 'sanitize' ), ) ); $wp_customize->add_control( new KIA_Customizer_Range_Control( $wp_customize, 'my_control', array( 'type' => 'kia-range', 'label' => __( 'Turn on setting', 'your-textomain' ), 'description' => __( 'An example toggle', 'your-textdomain' ), 'section' => 'my_section', 'settings' => 'my_setting', ) ) ); } add_action( 'customize_register', 'kia_customizer' );
Credits
Huge props to Rich Tabor's Login Designer and Per Soderlind's Customizer Toggle Control