How do I embed youtube videos into wordpress with javascript





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















anyone know a way to embed a YouTube video in javascript?
or a way to run a shortcode on a page in javascript?
I need a way to pass a javascript variable into a youtube url and embed the video. The code I have so far is using a plugin that runs this code as a shortcode on a page. using a plugin called Shortcoder.



I've done a lot of research and usually don't make new posts, but I can't seem to find the answer to this basic question. How do I embed a youtube video (or run a shortcode) from javascript. one thing I found is this that shows embedding a video with flashplayer, but I would like to avoid flashplayer if possible, and need it to be in javascript so I can pass a variable. Here's the code I found on youtube that I'm using to get the variable.



<script text="text/javascript">
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};

var video = getUrlParameter('v');

if(video){
console.log('v='+video);
// embed video with url

}else {
console.log('v=null');
// embed youtube uploads playlist

}


I need a way to embed a youtube video, or run the shortcode for the youtube wordpress plugin, but need the video url to be effected by my website url.



example: www.example.com/video/?v=Y123 should display the youtube video www.youtube.com/watch?v=Y123, and www.example.com/video/?v=x456 should display the youtube video www.youtube.com/watch?v=x456



I'm basically creating a youtube page for my videos, but plan to add a live chat that subs watching from my website can use from anywhere on the site while watching. I could also, possibly sometime in the future, add auto-pause videos for tutorials.



does anyone know a way to embed a YouTube video in javascript or a way to run a shortcode on a page in javascript?



a shortcode is prefered because it would remove a few extra limits and make future implementation of javascript into wordpress much easier.



Edit: also, I'm a bit new to wordpress, although have some experience in
android studio.










share|improve this question

























  • Why not use raw javascript?

    – DarkHeart Productions
    Nov 22 '18 at 4:38











  • can you provide an example on how to embed youtube videos with raw javascript?

    – SwiftNinjaPro
    Nov 22 '18 at 4:49











  • Gladly.........

    – DarkHeart Productions
    Nov 22 '18 at 4:52











  • Sorry, it will take a bit, I made a simplifier that uses YouTube videos as advertisements

    – DarkHeart Productions
    Nov 22 '18 at 4:55











  • I assume wordpress works with js, so when you get the video Id, create the element with word press and integrate using the YouTube api, when doing it, enter your id in the spot from wordpress

    – DarkHeart Productions
    Nov 22 '18 at 5:03


















0















anyone know a way to embed a YouTube video in javascript?
or a way to run a shortcode on a page in javascript?
I need a way to pass a javascript variable into a youtube url and embed the video. The code I have so far is using a plugin that runs this code as a shortcode on a page. using a plugin called Shortcoder.



I've done a lot of research and usually don't make new posts, but I can't seem to find the answer to this basic question. How do I embed a youtube video (or run a shortcode) from javascript. one thing I found is this that shows embedding a video with flashplayer, but I would like to avoid flashplayer if possible, and need it to be in javascript so I can pass a variable. Here's the code I found on youtube that I'm using to get the variable.



<script text="text/javascript">
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};

var video = getUrlParameter('v');

if(video){
console.log('v='+video);
// embed video with url

}else {
console.log('v=null');
// embed youtube uploads playlist

}


I need a way to embed a youtube video, or run the shortcode for the youtube wordpress plugin, but need the video url to be effected by my website url.



example: www.example.com/video/?v=Y123 should display the youtube video www.youtube.com/watch?v=Y123, and www.example.com/video/?v=x456 should display the youtube video www.youtube.com/watch?v=x456



I'm basically creating a youtube page for my videos, but plan to add a live chat that subs watching from my website can use from anywhere on the site while watching. I could also, possibly sometime in the future, add auto-pause videos for tutorials.



does anyone know a way to embed a YouTube video in javascript or a way to run a shortcode on a page in javascript?



a shortcode is prefered because it would remove a few extra limits and make future implementation of javascript into wordpress much easier.



Edit: also, I'm a bit new to wordpress, although have some experience in
android studio.










share|improve this question

























  • Why not use raw javascript?

    – DarkHeart Productions
    Nov 22 '18 at 4:38











  • can you provide an example on how to embed youtube videos with raw javascript?

    – SwiftNinjaPro
    Nov 22 '18 at 4:49











  • Gladly.........

    – DarkHeart Productions
    Nov 22 '18 at 4:52











  • Sorry, it will take a bit, I made a simplifier that uses YouTube videos as advertisements

    – DarkHeart Productions
    Nov 22 '18 at 4:55











  • I assume wordpress works with js, so when you get the video Id, create the element with word press and integrate using the YouTube api, when doing it, enter your id in the spot from wordpress

    – DarkHeart Productions
    Nov 22 '18 at 5:03














0












0








0








anyone know a way to embed a YouTube video in javascript?
or a way to run a shortcode on a page in javascript?
I need a way to pass a javascript variable into a youtube url and embed the video. The code I have so far is using a plugin that runs this code as a shortcode on a page. using a plugin called Shortcoder.



I've done a lot of research and usually don't make new posts, but I can't seem to find the answer to this basic question. How do I embed a youtube video (or run a shortcode) from javascript. one thing I found is this that shows embedding a video with flashplayer, but I would like to avoid flashplayer if possible, and need it to be in javascript so I can pass a variable. Here's the code I found on youtube that I'm using to get the variable.



<script text="text/javascript">
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};

var video = getUrlParameter('v');

if(video){
console.log('v='+video);
// embed video with url

}else {
console.log('v=null');
// embed youtube uploads playlist

}


I need a way to embed a youtube video, or run the shortcode for the youtube wordpress plugin, but need the video url to be effected by my website url.



example: www.example.com/video/?v=Y123 should display the youtube video www.youtube.com/watch?v=Y123, and www.example.com/video/?v=x456 should display the youtube video www.youtube.com/watch?v=x456



I'm basically creating a youtube page for my videos, but plan to add a live chat that subs watching from my website can use from anywhere on the site while watching. I could also, possibly sometime in the future, add auto-pause videos for tutorials.



does anyone know a way to embed a YouTube video in javascript or a way to run a shortcode on a page in javascript?



a shortcode is prefered because it would remove a few extra limits and make future implementation of javascript into wordpress much easier.



Edit: also, I'm a bit new to wordpress, although have some experience in
android studio.










share|improve this question
















anyone know a way to embed a YouTube video in javascript?
or a way to run a shortcode on a page in javascript?
I need a way to pass a javascript variable into a youtube url and embed the video. The code I have so far is using a plugin that runs this code as a shortcode on a page. using a plugin called Shortcoder.



I've done a lot of research and usually don't make new posts, but I can't seem to find the answer to this basic question. How do I embed a youtube video (or run a shortcode) from javascript. one thing I found is this that shows embedding a video with flashplayer, but I would like to avoid flashplayer if possible, and need it to be in javascript so I can pass a variable. Here's the code I found on youtube that I'm using to get the variable.



<script text="text/javascript">
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};

var video = getUrlParameter('v');

if(video){
console.log('v='+video);
// embed video with url

}else {
console.log('v=null');
// embed youtube uploads playlist

}


I need a way to embed a youtube video, or run the shortcode for the youtube wordpress plugin, but need the video url to be effected by my website url.



example: www.example.com/video/?v=Y123 should display the youtube video www.youtube.com/watch?v=Y123, and www.example.com/video/?v=x456 should display the youtube video www.youtube.com/watch?v=x456



I'm basically creating a youtube page for my videos, but plan to add a live chat that subs watching from my website can use from anywhere on the site while watching. I could also, possibly sometime in the future, add auto-pause videos for tutorials.



does anyone know a way to embed a YouTube video in javascript or a way to run a shortcode on a page in javascript?



a shortcode is prefered because it would remove a few extra limits and make future implementation of javascript into wordpress much easier.



Edit: also, I'm a bit new to wordpress, although have some experience in
android studio.







javascript wordpress video youtube embed






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 31 '18 at 15:05









Cœur

19.3k10116155




19.3k10116155










asked Nov 22 '18 at 4:29









SwiftNinjaProSwiftNinjaPro

125




125













  • Why not use raw javascript?

    – DarkHeart Productions
    Nov 22 '18 at 4:38











  • can you provide an example on how to embed youtube videos with raw javascript?

    – SwiftNinjaPro
    Nov 22 '18 at 4:49











  • Gladly.........

    – DarkHeart Productions
    Nov 22 '18 at 4:52











  • Sorry, it will take a bit, I made a simplifier that uses YouTube videos as advertisements

    – DarkHeart Productions
    Nov 22 '18 at 4:55











  • I assume wordpress works with js, so when you get the video Id, create the element with word press and integrate using the YouTube api, when doing it, enter your id in the spot from wordpress

    – DarkHeart Productions
    Nov 22 '18 at 5:03



















  • Why not use raw javascript?

    – DarkHeart Productions
    Nov 22 '18 at 4:38











  • can you provide an example on how to embed youtube videos with raw javascript?

    – SwiftNinjaPro
    Nov 22 '18 at 4:49











  • Gladly.........

    – DarkHeart Productions
    Nov 22 '18 at 4:52











  • Sorry, it will take a bit, I made a simplifier that uses YouTube videos as advertisements

    – DarkHeart Productions
    Nov 22 '18 at 4:55











  • I assume wordpress works with js, so when you get the video Id, create the element with word press and integrate using the YouTube api, when doing it, enter your id in the spot from wordpress

    – DarkHeart Productions
    Nov 22 '18 at 5:03

















Why not use raw javascript?

– DarkHeart Productions
Nov 22 '18 at 4:38





Why not use raw javascript?

– DarkHeart Productions
Nov 22 '18 at 4:38













can you provide an example on how to embed youtube videos with raw javascript?

– SwiftNinjaPro
Nov 22 '18 at 4:49





can you provide an example on how to embed youtube videos with raw javascript?

– SwiftNinjaPro
Nov 22 '18 at 4:49













Gladly.........

– DarkHeart Productions
Nov 22 '18 at 4:52





Gladly.........

– DarkHeart Productions
Nov 22 '18 at 4:52













Sorry, it will take a bit, I made a simplifier that uses YouTube videos as advertisements

– DarkHeart Productions
Nov 22 '18 at 4:55





Sorry, it will take a bit, I made a simplifier that uses YouTube videos as advertisements

– DarkHeart Productions
Nov 22 '18 at 4:55













I assume wordpress works with js, so when you get the video Id, create the element with word press and integrate using the YouTube api, when doing it, enter your id in the spot from wordpress

– DarkHeart Productions
Nov 22 '18 at 5:03





I assume wordpress works with js, so when you get the video Id, create the element with word press and integrate using the YouTube api, when doing it, enter your id in the spot from wordpress

– DarkHeart Productions
Nov 22 '18 at 5:03












2 Answers
2






active

oldest

votes


















0














videoId: The id after your video, ie, the video is of this is "1lD9G4D1p-Y" https://www.youtube.com/watch?v=1lD9G4D1p-Y



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

window.onYouTubePlayerAPIReady = function() {
window.player = new YT.Player('elementId');
window.player.cueVideoById({'videoId': 'yourVideoId',
'suggestedQuality': 'medium'});
}


The difference between my code and their's is mine adds the script using JavaScript, theirs adds it using HTML and then JavaScript to run it.



Documentation
https://developers.google.com/youtube/iframe_api_reference






share|improve this answer































    0














    ok, I think I figured a way for it to work. Here is what my code looks like, if anyone else needs it:



    <iframe name="videoURL" id="videoURL" width="560" height="315" src="https://www.youtube.com/embed/ymHNtBZxFKY" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

    <script text="text/javascript">
    var getUrlParameter = function getUrlParameter(sParam) {
    var sPageURL = decodeURIComponent(window.location.search.substring(1)),
    sURLVariables = sPageURL.split('&'),
    sParameterName,
    i;
    for (i = 0; i < sURLVariables.length; i++) {
    sParameterName = sURLVariables[i].split('=');
    if (sParameterName[0] === sParam) {
    return sParameterName[1] === undefined ? true : sParameterName[1];
    }
    }
    };

    var video = getUrlParameter('v');
    var url;

    if(video){
    console.log('v='+video);
    url = 'https://www.youtube.com/embed/'+video;
    // embed video with url

    }else {
    console.log('v=null');
    // embed youtube uploads playlist
    url = 'https://www.youtube.com/embed?listType=playlist&list=UU7YyXO5sOuG4zmGlW7KDCNw'
    }

    document.getElementById("videoURL").setAttribute("src", url);

    </script>





    share|improve this answer
























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423910%2fhow-do-i-embed-youtube-videos-into-wordpress-with-javascript%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      videoId: The id after your video, ie, the video is of this is "1lD9G4D1p-Y" https://www.youtube.com/watch?v=1lD9G4D1p-Y



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

      window.onYouTubePlayerAPIReady = function() {
      window.player = new YT.Player('elementId');
      window.player.cueVideoById({'videoId': 'yourVideoId',
      'suggestedQuality': 'medium'});
      }


      The difference between my code and their's is mine adds the script using JavaScript, theirs adds it using HTML and then JavaScript to run it.



      Documentation
      https://developers.google.com/youtube/iframe_api_reference






      share|improve this answer




























        0














        videoId: The id after your video, ie, the video is of this is "1lD9G4D1p-Y" https://www.youtube.com/watch?v=1lD9G4D1p-Y



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

        window.onYouTubePlayerAPIReady = function() {
        window.player = new YT.Player('elementId');
        window.player.cueVideoById({'videoId': 'yourVideoId',
        'suggestedQuality': 'medium'});
        }


        The difference between my code and their's is mine adds the script using JavaScript, theirs adds it using HTML and then JavaScript to run it.



        Documentation
        https://developers.google.com/youtube/iframe_api_reference






        share|improve this answer


























          0












          0








          0







          videoId: The id after your video, ie, the video is of this is "1lD9G4D1p-Y" https://www.youtube.com/watch?v=1lD9G4D1p-Y



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

          window.onYouTubePlayerAPIReady = function() {
          window.player = new YT.Player('elementId');
          window.player.cueVideoById({'videoId': 'yourVideoId',
          'suggestedQuality': 'medium'});
          }


          The difference between my code and their's is mine adds the script using JavaScript, theirs adds it using HTML and then JavaScript to run it.



          Documentation
          https://developers.google.com/youtube/iframe_api_reference






          share|improve this answer













          videoId: The id after your video, ie, the video is of this is "1lD9G4D1p-Y" https://www.youtube.com/watch?v=1lD9G4D1p-Y



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

          window.onYouTubePlayerAPIReady = function() {
          window.player = new YT.Player('elementId');
          window.player.cueVideoById({'videoId': 'yourVideoId',
          'suggestedQuality': 'medium'});
          }


          The difference between my code and their's is mine adds the script using JavaScript, theirs adds it using HTML and then JavaScript to run it.



          Documentation
          https://developers.google.com/youtube/iframe_api_reference







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 4:57









          DarkHeart ProductionsDarkHeart Productions

          565




          565

























              0














              ok, I think I figured a way for it to work. Here is what my code looks like, if anyone else needs it:



              <iframe name="videoURL" id="videoURL" width="560" height="315" src="https://www.youtube.com/embed/ymHNtBZxFKY" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

              <script text="text/javascript">
              var getUrlParameter = function getUrlParameter(sParam) {
              var sPageURL = decodeURIComponent(window.location.search.substring(1)),
              sURLVariables = sPageURL.split('&'),
              sParameterName,
              i;
              for (i = 0; i < sURLVariables.length; i++) {
              sParameterName = sURLVariables[i].split('=');
              if (sParameterName[0] === sParam) {
              return sParameterName[1] === undefined ? true : sParameterName[1];
              }
              }
              };

              var video = getUrlParameter('v');
              var url;

              if(video){
              console.log('v='+video);
              url = 'https://www.youtube.com/embed/'+video;
              // embed video with url

              }else {
              console.log('v=null');
              // embed youtube uploads playlist
              url = 'https://www.youtube.com/embed?listType=playlist&list=UU7YyXO5sOuG4zmGlW7KDCNw'
              }

              document.getElementById("videoURL").setAttribute("src", url);

              </script>





              share|improve this answer




























                0














                ok, I think I figured a way for it to work. Here is what my code looks like, if anyone else needs it:



                <iframe name="videoURL" id="videoURL" width="560" height="315" src="https://www.youtube.com/embed/ymHNtBZxFKY" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

                <script text="text/javascript">
                var getUrlParameter = function getUrlParameter(sParam) {
                var sPageURL = decodeURIComponent(window.location.search.substring(1)),
                sURLVariables = sPageURL.split('&'),
                sParameterName,
                i;
                for (i = 0; i < sURLVariables.length; i++) {
                sParameterName = sURLVariables[i].split('=');
                if (sParameterName[0] === sParam) {
                return sParameterName[1] === undefined ? true : sParameterName[1];
                }
                }
                };

                var video = getUrlParameter('v');
                var url;

                if(video){
                console.log('v='+video);
                url = 'https://www.youtube.com/embed/'+video;
                // embed video with url

                }else {
                console.log('v=null');
                // embed youtube uploads playlist
                url = 'https://www.youtube.com/embed?listType=playlist&list=UU7YyXO5sOuG4zmGlW7KDCNw'
                }

                document.getElementById("videoURL").setAttribute("src", url);

                </script>





                share|improve this answer


























                  0












                  0








                  0







                  ok, I think I figured a way for it to work. Here is what my code looks like, if anyone else needs it:



                  <iframe name="videoURL" id="videoURL" width="560" height="315" src="https://www.youtube.com/embed/ymHNtBZxFKY" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

                  <script text="text/javascript">
                  var getUrlParameter = function getUrlParameter(sParam) {
                  var sPageURL = decodeURIComponent(window.location.search.substring(1)),
                  sURLVariables = sPageURL.split('&'),
                  sParameterName,
                  i;
                  for (i = 0; i < sURLVariables.length; i++) {
                  sParameterName = sURLVariables[i].split('=');
                  if (sParameterName[0] === sParam) {
                  return sParameterName[1] === undefined ? true : sParameterName[1];
                  }
                  }
                  };

                  var video = getUrlParameter('v');
                  var url;

                  if(video){
                  console.log('v='+video);
                  url = 'https://www.youtube.com/embed/'+video;
                  // embed video with url

                  }else {
                  console.log('v=null');
                  // embed youtube uploads playlist
                  url = 'https://www.youtube.com/embed?listType=playlist&list=UU7YyXO5sOuG4zmGlW7KDCNw'
                  }

                  document.getElementById("videoURL").setAttribute("src", url);

                  </script>





                  share|improve this answer













                  ok, I think I figured a way for it to work. Here is what my code looks like, if anyone else needs it:



                  <iframe name="videoURL" id="videoURL" width="560" height="315" src="https://www.youtube.com/embed/ymHNtBZxFKY" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

                  <script text="text/javascript">
                  var getUrlParameter = function getUrlParameter(sParam) {
                  var sPageURL = decodeURIComponent(window.location.search.substring(1)),
                  sURLVariables = sPageURL.split('&'),
                  sParameterName,
                  i;
                  for (i = 0; i < sURLVariables.length; i++) {
                  sParameterName = sURLVariables[i].split('=');
                  if (sParameterName[0] === sParam) {
                  return sParameterName[1] === undefined ? true : sParameterName[1];
                  }
                  }
                  };

                  var video = getUrlParameter('v');
                  var url;

                  if(video){
                  console.log('v='+video);
                  url = 'https://www.youtube.com/embed/'+video;
                  // embed video with url

                  }else {
                  console.log('v=null');
                  // embed youtube uploads playlist
                  url = 'https://www.youtube.com/embed?listType=playlist&list=UU7YyXO5sOuG4zmGlW7KDCNw'
                  }

                  document.getElementById("videoURL").setAttribute("src", url);

                  </script>






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 22 '18 at 6:59









                  SwiftNinjaProSwiftNinjaPro

                  125




                  125






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423910%2fhow-do-i-embed-youtube-videos-into-wordpress-with-javascript%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      鏡平學校

                      ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

                      Why https connections are so slow when debugging (stepping over) in Java?