How do I embed youtube videos into wordpress with javascript











up vote
0
down vote

favorite












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 at 4:38










  • can you provide an example on how to embed youtube videos with raw javascript?
    – SwiftNinjaPro
    Nov 22 at 4:49










  • Gladly.........
    – DarkHeart Productions
    Nov 22 at 4:52










  • Sorry, it will take a bit, I made a simplifier that uses YouTube videos as advertisements
    – DarkHeart Productions
    Nov 22 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 at 5:03















up vote
0
down vote

favorite












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 at 4:38










  • can you provide an example on how to embed youtube videos with raw javascript?
    – SwiftNinjaPro
    Nov 22 at 4:49










  • Gladly.........
    – DarkHeart Productions
    Nov 22 at 4:52










  • Sorry, it will take a bit, I made a simplifier that uses YouTube videos as advertisements
    – DarkHeart Productions
    Nov 22 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 at 5:03













up vote
0
down vote

favorite









up vote
0
down vote

favorite











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 Nov 22 at 4:47

























asked Nov 22 at 4:29









SwiftNinjaPro

11




11












  • Why not use raw javascript?
    – DarkHeart Productions
    Nov 22 at 4:38










  • can you provide an example on how to embed youtube videos with raw javascript?
    – SwiftNinjaPro
    Nov 22 at 4:49










  • Gladly.........
    – DarkHeart Productions
    Nov 22 at 4:52










  • Sorry, it will take a bit, I made a simplifier that uses YouTube videos as advertisements
    – DarkHeart Productions
    Nov 22 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 at 5:03


















  • Why not use raw javascript?
    – DarkHeart Productions
    Nov 22 at 4:38










  • can you provide an example on how to embed youtube videos with raw javascript?
    – SwiftNinjaPro
    Nov 22 at 4:49










  • Gladly.........
    – DarkHeart Productions
    Nov 22 at 4:52










  • Sorry, it will take a bit, I made a simplifier that uses YouTube videos as advertisements
    – DarkHeart Productions
    Nov 22 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 at 5:03
















Why not use raw javascript?
– DarkHeart Productions
Nov 22 at 4:38




Why not use raw javascript?
– DarkHeart Productions
Nov 22 at 4:38












can you provide an example on how to embed youtube videos with raw javascript?
– SwiftNinjaPro
Nov 22 at 4:49




can you provide an example on how to embed youtube videos with raw javascript?
– SwiftNinjaPro
Nov 22 at 4:49












Gladly.........
– DarkHeart Productions
Nov 22 at 4:52




Gladly.........
– DarkHeart Productions
Nov 22 at 4:52












Sorry, it will take a bit, I made a simplifier that uses YouTube videos as advertisements
– DarkHeart Productions
Nov 22 at 4:55




Sorry, it will take a bit, I made a simplifier that uses YouTube videos as advertisements
– DarkHeart Productions
Nov 22 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 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 at 5:03












2 Answers
2






active

oldest

votes

















up vote
0
down vote













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




























    up vote
    0
    down vote













    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',
      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








      up vote
      0
      down vote













      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

























        up vote
        0
        down vote













        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























          up vote
          0
          down vote










          up vote
          0
          down vote









          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 at 4:57









          DarkHeart Productions

          565




          565
























              up vote
              0
              down vote













              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

























                up vote
                0
                down vote













                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























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  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 at 6:59









                  SwiftNinjaPro

                  11




                  11






























                      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.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • 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

                      A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                      Calculate evaluation metrics using cross_val_predict sklearn

                      Insert data from modal to MySQL (multiple modal on website)