-
AuthorPosts
-
February 18, 2015 at 8:40 am #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.February 18, 2015 at 3:47 pm #398197Hi teeramusic!
Can you please post the code you would like to use here using http://pastebin.com/ ?
Cheers!
YigitFebruary 19, 2015 at 7:35 am #398681teeramusic.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,
TeeraFebruary 19, 2015 at 5:59 pm #399083Hey!
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,
ElliottFebruary 20, 2015 at 6:10 am #399447this 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_scriptBut 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.
February 20, 2015 at 7:06 am #399464Hi!
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,
IsmaelFebruary 23, 2015 at 5:50 am #400385I’ve put it in functions.php but doesn’t seem to work :\
February 23, 2015 at 7:30 am #400407Hi!
Hmm.. I’m not sure why it’s not working. The best thing to do is to ask the script author.
Cheers!
IsmaelFebruary 23, 2015 at 8:35 am #400429Ahh nvm, I got it to work, thanks :)
-
AuthorPosts
- The topic ‘jQuery’ is closed to new replies.