How to Keep Elementor First Accordion Closed by Default

Pro Tip

Pro tip: if you font have elementor pro don't worry you can use html widget to put you custom css. After researching, trying and testing my team, I did found some simple methods by which you will be able to close the first accordion. if you don't know coding don't worry here give you full guide with code so no need to coding skill.

Hello, This blog post for you if you don’t know how to close your first accordion. If you try to learn and beginner and need to solve your issue to close elementor first accordion please try using below method that is working 100% for me.

Hope you like this and if you have any issue in elementor or WordPress our team ready to help you contact us

accordion closed by default

How to keep Elementor First Accordion Closed by Default ?

Using this script and css keep elementor first accordion closed by default Here is easy guide with image and also know you how to do free without buying elementor pro.

  1. Take a elementer HTML widget.
  2. Paste this JQuery and Css Code to Close Elementor Accordion in Html Widget.

<style class=”accordion-closed-on-load”>
body:not(.elementor-editor-active) .elementor-widget-accordion .elementor-tab-content {
display: none!important;
}
</style>

javascript
window.addEventListener('load', function() {
setTimeout(function(){
document.querySelector('.accordion-closed-on-load').remove();
let accordionsElems = document.querySelectorAll('.elementor-widget-accordion')
accordionsElems.forEach(e => {
let activeTitle = e.querySelector('.elementor-tab-title.elementor-active');
let activeContent = e.querySelector('.elementor-tab-content.elementor-active')
jQuery(activeContent).hide();
activeTitle.classList.remove('elementor-active');
activeContent.classList.remove('elementor-active');
activeContent.setAttribute('hidden','hidden');
activeTitle.setAttribute('aria-expanded',false);
activeTitle.setAttribute('aria-selected',false);
activeTitle.setAttribute('tabindex',-1);
});
},100);
});

Your html widget will look like below screenshot. 

Close Elementor Accordion

After add this your result will be like this.

How to Close Elementor Accordion

You can add above script so you will get your default open  Elementor Accordion is closed.

An HTML Widget that helps you Keep Elementor Accordion Closed by Default (Using JavaScript Code)

To close the first accordion item by default in Elementor, you can follow these steps:

Step 1: Copy the below-provided Javascript code…

<script>
jQuery(document).ready(function($) {
var delay = 100; setTimeout(function() {
jQuery('.elementor-tab-title').removeClass('elementor-active');
 jQuery('.elementor-tab-content').css('display', 'none'); }, delay);
});
</script>

Step 2: Just above your accordion widget, place an “HTML Widget” from the elements panel & paste the above-provided Javascript code inside the HTML Code.

Step 3: Once done, publish or update the page, see it live & shout – Yes, I got the shit done! Just kidding, that’s all you need to set the elementor accordion start as closed.

Custom Code in Elementor Pro:

<script>
    $('.elementor-tab-title').removeClass('elementor-active');
    $('.elementor-tab-content').css('display', 'none');    
</script>

If you have multiple accordions on your website and want to make them all closed by default, follow these steps:

    • Go to Elementor -> Custom Code in your WordPress dashboard.
    • Click the Add new button to create a new custom code snippet.
    • Give your custom code a name and paste the JavaScript code provided above.
    • Choose the location (header, footer, or body) where your code should work.
    • Click the Publish button to apply the code.
    • Reload one of the pages on your website that contains an accordion to check the result.

Elementor Pro Advanced Tab

Set the CSS class “closeAccordion” for the accordion widgets you want to close by default.

<style>
    .closeAccordion .elementor-tab-content {
        display: none;
    }       
</style>

How To Apply

  • Click on the Advanced tab of the desired accordion widget.
  • Enter “closeAccordion” in the CSS Classes box.
  • Create a custom code in Elementor Pro and paste the provided CSS code.
  • Save the changes.

ElementsKit

This addon offers a one-click setting to keep the first slide as closed or opened and also, settings on individual items of the accordion to keep them active/inactive. What I liked about ElementsKit is it offers 25+ ready-to-import elementor accordion templates for faster workflow.

ElementsKit Lite Accordion Widget Options

Essential Addons

Similar to ElementsKit, it offers settings with the name “Active as Default” on Individual accordion items to set them as closed or open. By default, all the accordions are inactive.

Essential Addons Accordion Widget Options

Elementor Hooks

Utilize Elementor hooks to inject custom JavaScript code that closes the accordion sections by default. This method allows for precise control over when and how the code is executed within Elementor’s rendering process.

elementor hook

function close_accordion_default() {
?>
<script>
jQuery(document).ready(function($) {
$(‘.elementor-accordion .elementor-tab-content’).hide();
});
</script>
<?php
}
add_action(‘wp_footer’, ‘close_accordion_default’);

How To Apply

  • Click on the Theme file editor inner Appearance item.step 1
  • Added above code in function.php file than update your code.

other technique you may also like

  • Widget Settings: Within the Elementor editor, access the accordion widget settings and specify the default state as closed. This ensures all accordion sections remain collapsed upon page load.
  • Custom CSS Styling: Utilize custom CSS to override the default behavior of Elementor accordions. Target the accordion elements and set their initial display property to “none” to keep them closed until interacted with.
  • JavaScript Initialization: Implement JavaScript code to control the behavior of Elementor accordions. Use jQuery to programmatically set the accordion sections to a closed state upon page load.
  • Elementor Hooks: Utilize Elementor hooks to inject custom JavaScript code that closes the accordion sections by default. This method offers precise control over when and how the code is executed within Elementor’s rendering process.
  • Elementor Template Overrides: Create a custom Elementor template for the accordion widget and apply custom JavaScript to close the accordion sections by default. This provides a structured approach for managing customizations within Elementor’s framework.
  • Using Elementor Actions: Leverage Elementor actions to insert custom JavaScript code into specific areas of the page, such as the footer, to close accordion sections by default. This offers flexibility in where and how the JavaScript code is applied within Elementor’s structure.
  • Consider User Experience: While keeping accordions closed by default can streamline the page layout, consider user experience implications. Ensure that users understand how to interact with the accordions to reveal additional content.

Conclusion

Hope you like and enjoy code if you still having issue with any thing let me know I just open comment box for you. Also want to share one more secret  with you if your any jQuery code not working use “jQuery” in place of  “$” try this and let me know if work for you.

FAQ

  • Yes, one of the key strengths of Elementor Accordion is its compatibility with other Elementor elements. You can effortlessly integrate accordion widgets with various elements like buttons, images, and text to create dynamic and engaging web pages. This flexibility opens up endless possibilities for creative and interactive design.

  • To make the most of Elementor Accordion, consider the following best practices:

    • Use concise and compelling headings for accordion sections.
    • Test the responsiveness on different devices during the design phase.
    • Experiment with different styling options to align with your brand identity.
  • Yes, within the Elementor editor, you can access the settings of the accordion widget and specify the default state as closed. This setting ensures that all accordion sections start in a collapsed state.

  • Absolutely. By applying custom CSS, you can override the default behavior of Elementor accordions. Target the accordion elements and set their initial display property to “none” to keep them closed until interacted with.

  • By default, the first item of the Accordion widget in Elementor is expanded, while all other items remain collapsed. If you want to keep all items closed initially, you can achieve this using JavaScript or Elementor add-ons like JetTabs or Essential Addons

  • Unfortunately, the default Accordion widget in Elementor doesn’t allow adding image-based content  However, you can install Elementor add-ons like JetTabs or Essential Addons to create image accordions

  • Yes, there are several free elementor accordion widgets available. To name a few – ElementsKit, ElementPack, Powerpack, etc add-ons provide free elementor accordion widgets along with templates that you can use on your website.

Leave a Reply

Your email address will not be published. Required fields are marked *

In a Rush? Dive into Our Bite-Sized Web Stories!

If time is tight, explore our web stories—they’ll help you achieve your goals faster.

Facebook
Twitter
WhatsApp