• 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="https://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…

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi cielle. Since you’re using a commercial theme I’d recommend you post your question on the Elegant Themes theme support site:
    https://www.elegantthemes.com/forum/
    The users and developers there are familiar with the theme functionality and would be better able to answer your question. Also, these forums are for support of themes available in the www.ads-software.com repository and the volunteers on this forum don’t have access to commercial products. Contacting the vendor also allows the developers to be aware of potential issues with their products.

    Thread Starter cielle

    (@cielle)

    Thanks bdbrown…
    I did think of doing that but they are there in order to sort out issues to do with their Theme and any problems with that etc as far as i know…
    Not to help with general wordpress and javascript etc…
    I need help with the syntax ( not sure if this is the right word ) of the javascript and where it should go and how it should be called etc.. and so thought that this would be the best place to get advice on that …
    But ok, I will give that a try and see how i go…
    Will come back to this thread if needed…

    I think that i don’t need to have the call to jquery? Since Divi already does that?

    It’s things like this that the vendor needs to answer.

    Thread Starter cielle

    (@cielle)

    yes, that part certainly…

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to add javascript to child theme…’ is closed to new replies.