Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #397982

    Any way to access jQuery from content element code block? I can’t get it to work.
    I also want to add youtube api in a code block if possible.

    #398197

    Hi teeramusic!

    Can you please post the code you would like to use here using http://pastebin.com/ ?

    Cheers!
    Yigit

    #398681

    http://pastebin.com/HC0wiDJi

    teeramusic.com

    This is what I have right now. Basically it allows only 1 video to play at a time. It was working okay, except now I also have the post entry with the youtube video.

    I had wanted to write the script above using jQuery, but I can’t get it to work… so this was my solution. Which worked until now.

    Also, I can’t get onYouTubeIframeAPIReady to be triggered when the Youtube video in the blog entry loads except when I put the script in the tracking code, but I don’t want to do that because I don’t want it in every page.

    Thanks,
    Teera

    #399083

    Hey!

    It’s some pretty advanced scripting. You can learn how to do it here, https://developers.google.com/youtube/js_api_reference. It would be best to hire a freelancer out if you have troubles though.

    If your trying to do something specific then let us know and we may be able to offer some alternatives.

    Best regards,
    Elliott

    #399447

    this script:

     <script>
        
          var tag = document.createElement('script');
    
          tag.src = "https://www.youtube.com/iframe_api";
          var firstScriptTag = document.getElementsByTagName('script')[0];
          firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
    
         
          function onYouTubeIframeAPIReady() {
          console.log('stuff is working');
          }
    </script>

    works on a simple page like this:
    http://www.w3schools.com/html/tryit.asp?filename=tryhtml_script

    But not when I put it in enfold code block and I want to know why.

    For now I just want to only allow one video to play at a time, but in the future I intend to add some functions.

    It only seems to work if I put it in the Google analytics box, but I don’t want all of my scripts to load on every page.

    #399464

    Hi!

    Try this on functions.php:

    add_action('wp_footer', 'ava_current_menu');
    function ava_current_menu(){ if(is_page('Home')) {
    ?>
    <script>
    (function($){
      var tag = document.createElement('script');
    
      tag.src = "https://www.youtube.com/iframe_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
    
     
      function onYouTubeIframeAPIReady() {
      console.log('stuff is working');
      }
      
      //onYouTubeIframeAPIReady();
    })(jQuery);
    </script>
    <?php
    }}

    Use the is_page() conditional function if you want to apply it on a specific page:

    Regards,
    Ismael

    #400385

    I’ve put it in functions.php but doesn’t seem to work :\

    #400407

    Hi!

    Hmm.. I’m not sure why it’s not working. The best thing to do is to ask the script author.

    Cheers!
    Ismael

    #400429

    Ahh nvm, I got it to work, thanks :)

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘jQuery’ is closed to new replies.