Where to add a jquery snippet
-
Hi,
I’d like to try out this ripple effect effect (jQuery).
https://github.com/andyvr/water-rippleIt needs jQuery. However, I’ve noticed that jQuery is already loaded from wp-includes:
<script type='text/javascript' src='https://wp:8888/wp-includes/js/jquery/jquery.js?ver=1.12.4-wp'></script> <script type='text/javascript' src='https://wp:8888/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.4.1'></script>
So I assume it’s ok as long as jquery loads before the ripple script.
The jquery call above is in the head section of html.
The js scripts that I’m loading in my theme are located towards the end of the body tag:<script type='text/javascript' src='https://wp:8888/wp-content/themes/Atheme/js/navigation.js?ver=20151215'></script> <script type='text/javascript' src='https://wp:8888/wp-content/themes/Atheme/js/ripple.js?ver=1'></script> <script type='text/javascript' src='https://wp:8888/wp-content/themes/Atheme/js/skip-link-focus-fix.js?ver=20151215'></script>
The middle one is the ripple one for the effect. Now the effect documentation recommends to call the effect by:
<script type="text/javascript"> $(document).ready(function() { $("#ripple").waterripple(); }); </script>
Shall I put it on the page template (it’s only one page that would have it) or load it somehow from functions.php.
I included it in the relevant template file like that:get_header('nav'); ?> <div id="primary" class="content-area"> <main id="main" class="site-main"> <section id="hero"> <?php get_template_part( 'template-parts/hero-wave' ); ?> </section> <?php while ( have_posts() ) : the_post(); ?> <div id="home_content" class="container aligncenter"><?php the_content(); ?></div> <?php endwhile; // End of the loop. ?> </main><!-- #main --> </div><!-- #primary --> <script type="text/javascript"> $(document).ready(function() { $("#ripple").waterripple(); }); </script> <?php get_footer('main');
But it didn’t work. The console showed the error:
TypeError: $ is not a function
Which, in my limited experience, would probably mean that jQuery hasn’t been loaded.
Please advise.
- The topic ‘Where to add a jquery snippet’ is closed to new replies.