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.
javascript wordpress video youtube embed
add a comment |
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.
javascript wordpress video youtube embed
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
add a comment |
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.
javascript wordpress video youtube embed
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
javascript wordpress video youtube embed
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
add a comment |
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
add a comment |
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
add a comment |
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>
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 22 at 4:57
DarkHeart Productions
565
565
add a comment |
add a comment |
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>
add a comment |
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>
add a comment |
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>
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>
answered Nov 22 at 6:59
SwiftNinjaPro
11
11
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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