0

I need to use the extra powers of the swfobject api. This object is a new way of embedding Youtube videos into web sites.

Pasting code that I found from Google's tutorial directly into the WordPress editor was in-effective. WordPress would not treat this as active code.

So, I created a new template file and inserted my code into that file. This worked relatively well. The code went live and I got the extra feature that I was looking for, which was that I am able to have the visuals of the video autoplay, and to have the sound muted by default.

However, this has messed up the layout and flow of my menus which where just above the video.

Can anyone tell me where to proper place to put this code is, or is this question too specific. If it will help you can see the messed up page at:

http://bestoftimesusa.com/home-mute-test/

and how it is supposed to look at:

http://bestoftimesusa.com

The fully functional code that got embedded is this:

                <script type="text/javascript" src="/wp-includes/js/swfobject/swfobject.js"></script>    

                 <div id="ytapiplayer">
                       You need Flash player 8+ and JavaScript enabled to view this video.
                 </div>

                 <script type="text/javascript">
                   var ytplayer = false;
                   var params = { allowScriptAccess: "always" };
                   var atts = { id: "myytplayer" };
                   swfobject.embedSWF("http://www.youtube.com/v/IBjstQceGBk?enablejsapi=1&playerapiid=ytplayer&version=3&autoplay=1",
                       "ytapiplayer", "370", "238", "8", null, null, params, atts);


                   function onYouTubePlayerReady(playerId) {
                      ytplayer = document.getElementById("myytplayer");
                      ytplayer.mute();

                      }

                    </script>
                    </div>
1
  • Your not-working example is returning 404
    – Jure C.
    Jun 26, 2012 at 21:50

1 Answer 1

0

Unless you want the same youtube video to appear on all pages (of a certain type), I don't think putting that entire block in your template files makes sense. The only part that really makes sense for a template file is the first line. The lines after that are video-specific.

By default, WordPress filters out javascript from posts. You can disable that filtering with a plugin which would allow you to include javascript in your posts.

Using that plugin, you can set javascript filters on a global or per-post basis. It seems like a per-post basis would work for you so I'd go with that, just enabling it on the page I wanted.

Two last things:

  • You could put the first line in one of your template files to eliminate having to put that in every post
  • You have one opening <div> tag but two closing </div> tags, that could be expected, but I'd double check.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.