The Switcher option is a visual toggle control that adds an on/off switch to your custom widget’s settings. It provides a clear, user-friendly way to enable or disable a feature or choose between two simple states.
Why would someone use it in a custom widget? #
Use a Switcher control whenever you need a simple binary choice, like showing/hiding an element, enabling an animation, or toggling a style mode. It’s more intuitive than a checkbox and clearly communicates an active/inactive state.
Where This Option Appears #
- In Widget Builder: You add this control in the Content tab.
- In the Elementor Editor: Once saved, it appears as a horizontal slider switch with customizable labels (like “Yes”/”No” or “Show”/”Hide”) right in your widget’s settings panel.
Available Settings #
Here are the configurable settings for the Switcher control:
Basic Settings #
- Label: The name of the control shown above the switch (e.g., “Show Icon”, “Enable Parallax”).
- Name: The unique machine-readable ID (like
show_icon) for the dynamic shortcode. - Description: Optional helper text below the control.
- Label On: The text displayed next to the switch when it is in the ON (checked) position (e.g., “Yes”, “Show”, “Enabled”).
- Label Off: The text displayed when it is in the OFF (unchecked) position (e.g., “No”, “Hide”, “Disabled”).
- Return Value: The actual value that the shortcode
{{name}}will output when the switch is ON. You can customize this (default isyes). - Default Value: Sets the starting state of the switch (On or Off).
Advanced Settings #
- Show Label, Label Block, Responsive Control: Standard visibility and layout options.
- Dynamic Support: When enabled, the switch’s state can be controlled by a dynamic source (though this is a less common use case).
- Frontend Available: When enabled, the switch’s value (
yes/noor your custom return value) is passed to your widget’s frontend JavaScript. - Separator, Conditions, Control Classes: Standard advanced options for layout and logic.
Generated Shortcode #
When you add a Switcher control with the Name show_title, Widget Builder generates the shortcode: {{show_title}}.
- What it represents: This shortcode outputs the Return Value (e.g.,
yes) if the switch is ON. If the switch is OFF, it outputs an empty string or a falsey value. - Where to use it:
- HTML Panel: Perfect in conjunction with a Condition attribute to include/exclude markup:
<h3 class="title" data-show="{{show_title}}">My Title</h3>. - CSS Panel: To apply conditional styles:
.title { display: {{show_title}}; }(This would setdisplay: yes;which is invalid. Better practice is shown below). - JS Panel: To control logic:
if ( '{{show_title}}' === 'yes' ) { // show the title }.
- HTML Panel: Perfect in conjunction with a Condition attribute to include/exclude markup:
How to Use It: A Practical Example #
Let’s create a “Card” widget where the user can choose to show or hide the card’s footer.
- In Widget Builder’s Content tab, add a Switcher control.
- Set the Label to
Show Footer. - Set Label On to
Showand Label Off toHide. Keep the Return Value asyes. - Set the Default Value to
Yes(On). - In your HTML panel, wrap the footer HTML in a conditional check:
<div class=”card-body”>Main Content</div> {{show_footer}} <div class=”card-footer”>Footer Content</div> {{/show_footer}}
(Note: This pseudo-code illustrates the concept. Actual conditional rendering might use different syntax specific to Widget Builder or be handled via CSS/JS.) - A more common method is using the value in CSS:
.card-footer { display: {{show_footer}} ? block : none; }(This requires JS logic. Often, you’d use a CSS class controlled by the shortcode).
Practical CSS/JS Method: Add a CSS class to the footer element that is controlled by the switcher’s value.
- HTML:
<div class="card-footer {{show_footer}}">Footer</div>(When ON, class becomescard-footer yes). - CSS:
.card-footer.yes { display: block; } .card-footer:not(.yes) { display: none; }
Common Use Cases #
- Visibility Toggles: Show or hide elements like titles, icons, dividers, or entire sections.
- Feature Activation: Enable/disable animations, hover effects, sticky behavior, or custom scripts.
- Style Mode Selectors: Switch between simple style alternatives (e.g., “Simple”/”Detailed” view) often paired with Conditions to show different setting sets.
- Boolean Logic Driver: The primary control for Conditions that show/hide other, more complex controls.
Helpful Tips #
- Use Clear, Action-Oriented Labels: A label like “Show Divider” with “On”/”Off” states is clearer than a vague “Divider State”.
- Customize Return Values for Clarity: For a “Style Mode” switcher, you could set Return Value to
detailedinstead ofyes. This makes your code more readable:if ( '{{style_mode}}' === 'detailed' ). - It’s the Perfect Conditional Trigger: The Switcher is the most intuitive control to use as the condition for showing/hiding groups of other options. Use the Conditions feature liberally.
- Test the Output: Remember, the shortcode outputs the text string of your Return Value. Ensure your HTML, CSS, or JS logic is checking for that exact string.
The Switcher is a fundamental control for creating interactive, user-friendly widget interfaces. It simplifies complex choices into a single, clear action.
Frequently Asked Questions #
What is the Switcher control used for?
The Switcher is a visual toggle control that adds an on/off slider switch to your custom widget’s settings. It is best for simple binary choices such as showing or hiding an element, enabling an animation, or toggling a style mode, and it communicates an active or inactive state more intuitively than a checkbox. You add it in the Content tab of Widget Builder.
How do I change the text shown next to the switch?
Use the Label On and Label Off settings. Label On is the text displayed when the switch is in the ON (checked) position, such as “Yes”, “Show”, or “Enabled”, and Label Off is the text shown when it is OFF, such as “No”, “Hide”, or “Disabled”. The Label setting above the switch names the control itself, for example “Show Icon”.
What value does the Switcher shortcode output?
The shortcode outputs the Return Value when the switch is ON, which defaults to yes, and an empty or falsey value when the switch is OFF. So a Switcher named show_title produces {{show_title}}, returning yes when enabled. You can customize the Return Value, for example setting it to detailed so your code reads if ( ‘{{style_mode}}’ === ‘detailed’ ).
Can I use the Switcher to show or hide other controls?
Yes, the Switcher is the most intuitive control to use as a Conditions trigger. Because it produces a clear true/false style value, you can use it to conditionally show or hide groups of other settings in your widget, such as revealing a detailed set of options only when the switch is ON. The documentation recommends using the Conditions feature liberally with it.
Does the Switcher value reach my frontend JavaScript?
Yes, if you enable the Frontend Available option in the Advanced settings. When enabled, the switch’s value (yes/no or your custom Return Value) is passed to your widget’s frontend JavaScript so you can drive interactive behavior. Just make sure your HTML, CSS, or JS logic checks for the exact string your Return Value produces.
