How to add javascript to child theme…
-
Hi and thank you for your help…
I have a javascript that I want to add to my Divi Child Theme and which i want to run on one specific page… let’s say page id=9…
It is a shuffle script… I want it to be added in the right way, whatever that is… but don’t at all know how to do that or what that is…
From what i gather i add something to my functions.php file?
Do I need to have the script itself somewhere else?Can someone please help me?
Here is the code that i have, but it was like this when i was using the Thesis Theme, which I am no longer using… ( and i can’t remember how i had done it then anyway.. ) so not sure what to do with it and how to put it all together now that i have a Child Theme…
function my_div_shuffler() { if (is_page(9)){ ?> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script> (function($){ $.fn.shuffle = function() { var allElems = this.get(), getRandom = function(max) { return Math.floor(Math.random() * max); }, shuffled = $.map(allElems, function(){ var random = getRandom(allElems.length), randEl = $(allElems[random]).clone(true)[0]; allElems.splice(random, 1); return randEl; }); this.each(function(i){ $(this).replaceWith($(shuffled[i])); }); return $(shuffled); }; })(jQuery); </script> <script type="text/javascript"> $(document).ready(function() { $('div.pink,div.yellow,div.turquoise,div.lavender,div.red').shuffle(); }); </script> <?php } } add_action('wp_head', 'my_div_shuffler');I think that i don’t need to have the call to jquery? Since Divi already does that?
Thank you so much in advance for your help…
The topic ‘How to add javascript to child theme…’ is closed to new replies.