Support » Plugin: Auto Hide Admin Bar » Assumes jQuery loads first

  • Useful plugin – except that in auto-hide-admin-bar.php there’s a MASSIVE inline <script></script closure that assumes jQuery has been loaded beforehand.

    So, if you load jQuery in the footer, this plugin fails.

    An approach to correct this would be:-

    • Move the <script> code to an external file
    • Amend the script so that it references the PHP data it needs via a javascript global array (eg $ahab)
    • Before the next section, assign all php data the script will need into the global javascript array such as around line 111:-

      <script>
      $ahab = {
      “theme_name”: <?php echo $theme_name,
      “ahab_anim_speed”: <?php echo $ahab_anim_speed; ?>,
      “ahab_delay”: <?php echo $ahab_delay; ?> ,
      “ahab_interval”: <?php echo $ahab_interval; ?>
      };

      </script>

    • wp_enqueue_script the external script so that it comes after jQuery has loaded
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Assumes jQuery loads first’ is closed to new replies.