• Resolved creativecatapps

    (@creativecatapps)


    When I installed sp_faq, the accordions wouldn’t work because of the hard-coded insertion of your jquery on line 163-171 of faq.php. It’s loading this before jQuery is loaded, so I’m getting an uncaught reference error as my jquery is enqueued in the footer of the site, per best practice.

    You’ve enqueued the css files and the jQuery accordion file itself, so can you not do something like:

    function sp_faq_script() { ?>
        <script type="text/javascript">
        jQuery(document).ready(function() {
            jQuery('.faq-accordion [data-accordion]').accordionfaq({
    	    singleOpen: <?php echo $faqsingleOpen; ?>,
                transitionEasing: 'ease',
                transitionSpeed: <?php echo $faqtransitionSpeed; ?>
            });
        });
        </script>
    <?php }
    add_action( 'wp_footer', 'sp_faq_script',100 );

    Please let me know whether this is viable, as I don’t want to overwrite core files (in case of updates) and certainly don’t want to spend any more time or money until I know it will work.

    Thanks,
    Emma

    https://www.ads-software.com/plugins/sp-faq/

Viewing 1 replies (of 1 total)
  • Thread Starter creativecatapps

    (@creativecatapps)

    Ok, so a bit more tweaking and I have a solution that works for me (disclaimer for anyone that chooses to try it: obviously this a core file override – any updates will likely overwrite this code and you’re back to square one):

    Underneath this code (lines 106-111):

    if( $transition_speed != '' ) {
    		$faqtransitionSpeed = $transition_speed;
    	} else {
    		$faqtransitionSpeed = '300';
    	}

    Add

    ?>
    	<script type="text/javascript">
    	var jsfaqsingleOpen = <?php echo $faqsingleOpen; ?>;
    	var jsfaqtransitionSpeed = <?php echo $faqtransitionSpeed; ?>;
    	</script>
    	<?php

    THEN, remove (lines 168-176):

    <script type="text/javascript">
          jQuery(document).ready(function() {
            jQuery('.faq-accordion [data-accordion]').accordionfaq({
    		 singleOpen: <?php echo $faqsingleOpen; ?>,
    		 transitionEasing: 'ease',
              transitionSpeed: <?php echo $faqtransitionSpeed; ?>
    		});
          });
        </script>

    And add the following at line 208:

    function sp_faq_script() { ?>
        <script type="text/javascript">
        jQuery(document).ready(function() {
            jQuery('.faq-accordion [data-accordion]').accordionfaq({
    			singleOpen: jsfaqsingleOpen,
                transitionEasing: 'ease',
                transitionSpeed: jsfaqtransitionSpeed
            });
        });
        </script>
    <?php }
    add_action( 'wp_footer', 'sp_faq_script',100 );

    Clear any caches if you have them and reload the page ??

    Cheers,
    Emma

Viewing 1 replies (of 1 total)
  • The topic ‘Possible solution for broken accordion’ is closed to new replies.