Advertisement
slothwit17

Rank Math FAQ Accordion with additional jQuery CDN

Aug 18th, 2023
2,133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.99 KB | None | 0 0
  1. /**
  2.  * Convert Rank Math FAQ Block Into Accordion
  3.  */
  4. function turn_rm_faq_to_accordion() {
  5.     ?>
  6.     // First try loading jQuery from Google's CDN
  7.     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
  8.     // Fall back to a local copy of jQuery if the CDN fails
  9.     <script>
  10.         window.jQuery || document.write('<script src="http://mysite.com/jquery.min.js"><\/script>'))
  11.     </script>
  12.     <script>
  13.         jQuery(document).ready(function() {
  14.             var faqBlock = jQuery("div#rank-math-faq");
  15.             var faqItems = faqBlock.find("div.rank-math-list-item");
  16.             faqItems.bind("click", function(event) {
  17.                 var answer = jQuery(this).find("div.rank-math-answer");
  18.                 if (answer.css("overflow") == "hidden") {
  19.                     answer.css("overflow", "visible");
  20.                     answer.css("max-height", "100vh");
  21.                 } else {
  22.                     answer.css("overflow", "hidden");
  23.                     answer.css("max-height", "0");
  24.                 }
  25.             });
  26.         });
  27.     </script>
  28.     <?php
  29. }
  30. add_action( 'wp_footer', 'turn_rm_faq_to_accordion' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement