Support

Account

Home Forums Front-end Issues Force 1st Accordion Open on Page Load

Solved

Force 1st Accordion Open on Page Load

  • Hi, I know that you can set an accordion to be open but when a person has opened a different one and goes back it remembers which they had open.

    I would like to force the first accordion open on page load no matter what. I figure there are two options here.

    1 – Force with JavaScript, or
    2 – can I link directly to an accordion?

    Any ideas?

    P.S. this is for a front-end form.

  • OK, Well, I think I solved my problem. The following code added to the functions file will force the first accordion open.

    add_action('acf/input/admin_head', 'my_acf_input_admin_head');
    function my_acf_input_admin_head() {
    ?>
    <script type="text/javascript">
    jQuery(function(){
      jQuery('.acf-accordion').removeClass('-open');
      jQuery('.acf-accordion:first-of-type').addClass('-open');
    });
    </script>
    <?php
    }
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Force 1st Accordion Open on Page Load’ is closed to new replies.