FAQ accordion – first item open

#580510
  • Resolved Anonymous
    Rank Math free

    Hi there,

    Thanks for the great FAQ block (love it!).

    I’m using the code you’ve offered from Silvan Hagen to turn it into an accordion.

    Just one question, though – is there a way to have the top FAQ accordion item open as the default when it loads (but still able to be closed, like all the others).

    Cheers!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    Thank you for your query, and we are so sorry about the trouble this must have caused.

    We tried using the code snippets on our local installation provided by Silvan Hagen available here: https://silvanhagen.com/writing/rankmath-faq-block-accordion/

    Looks like the codes does not work as expected on our end.

    Since it works on your intallation and you want to make improvements to it we might need the URL where you are using the Rank Math FAQ Blocks to help you with any code modification or hooks.

    Can you please share the URLs with us? So that we can investigate the issue further for you.

    We really look forward to helping you.

    Thank you.

    Anonymous
    Rank Math free

    Thank you very much for offering to have a look at this, Alhan.

    You can see an example of the FAQ block towards the top of this post: https://www.timetravelturtle.com/island-of-delos-tour-greece/

    As you’ll see, all three FAQ items in the block are closed. I was hoping for a solution so the top one will start in the open position.

    Cheers.

    Hello,

    In this case, we have modified the JS code a bit to ensure the first FAQ item is open upon page load.

    Please replace the JS code with this:

    (function ($) {
        var rankMath = {
            accordion: function () {
                $('.rank-math-block').find('.rank-math-answer').hide(); // hides all answers by default
                $('.rank-math-block').find('.rank-math-answer:first').slideDown(); // open the first answer
    
                $('.rank-math-block').find('.rank-math-question').click(function () {
                    // Expand or collapse this panel
                    $(this).nextAll('.rank-math-answer').eq(0).slideToggle('fast', function () {
                        if ($(this).hasClass('collapse')) {
                            $(this).removeClass('collapse');
                        } else {
                            $(this).addClass('collapse');
                        }
                    });
                    // Hide the other panels
                    $(".rank-math-answer").not($(this).nextAll('.rank-math-answer').eq(0)).slideUp('fast');
                });
    
                $('.rank-math-block .rank-math-question').click(function () {
                    $('.rank-math-block .rank-math-question').not($(this)).removeClass('collapse');
                    if ($(this).hasClass('collapse')) {
                        $(this).removeClass('collapse');
                    } else {
                        $(this).addClass('collapse');
                    }
                });
            }
        };
    
        rankMath.accordion();
    })(jQuery);

    Hope that helps and please do not hesitate to let us know if you need my assistance with anything else.

    Anonymous
    Rank Math free

    That’s fantastic – and works perfectly!

    Thanks so much for a great solution (and for getting it to me so quickly). Really appreciate your help!!

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)

The ticket ‘FAQ accordion – first item open’ is closed to new replies.