Below is my code and only video 1 can stop video 2 but video 2 can not stop video 1. I want one video to play at one time. What could be the reason and i am using shortcode and below is my code in functions.php file. I have two iframe youtube videos in my page html.



        function myalert(){?>
        <script type="text/javascript">

        var tag = document.createElement('script');

        tag.src = "https://www.youtube.com/iframe_api";
        var firstScriptTag = document.getElementsByTagName('script')[0];
        firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

        var player;
              function onYouTubeIframeAPIReady() {
                player0 = new YT.Player( 'player0', {
                  events: { 'onStateChange': first }
               player1 = new YT.Player( 'player1', {
                  events: { 'onStateChange': second }


        function first(event) {

          var video = jQuery("#player1").attr("src");

 function second(event) {

          var video1 = jQuery("#player0").attr("src");

  • Please read wordpress.stackexchange.com/questions/73082/…. – fuxia Jul 2 '15 at 1:15
  • @toscho I don't think the link you provided is in anyway related to my youtube api question .. if really so please elaborate. Thanks – Zeeshan Jul 2 '15 at 10:34
  • A shortcode has to return a string, it must not create output immediately. Maybe your shortcode callback is printing its content too early in the source code. Fix the callback function, and if the issue still exists, update your question. – fuxia Jul 2 '15 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.