T.Doe T.Doe - 11 days ago 5
HTML Question

How can I embed a youtube video in a Wordpress template page?

I create a new template page for one of the pages on my wordpress site because all I want on on that page is some text and a youtube video. From what I understand, Wordpress doesn't accept simply embedding a youtube video within your code, you must use the YouTube Player API. But to be honest it's not very clear to me how to apply it to my current code. Can anybody help, or provide some advice?

<?php /* Template Name: Black Ballad Crowdfunding Subscriptions*/ ?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>

<head>
<?php get_header(); ?>
<title>Black Ballad Crowdfunding</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="style.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>

<script>
$(document).ready(function(){
$("#more1").click(function(){
$(".reveal1").slideToggle("slow");
$(".video-container1").slideToggle("slow");
});
});
</script>
</head>

<body>

<div class="container">

<div id="intro">
<p>Some text.</p>
<p class="reveal1">Some more text.
<div class="video-container1" align="center">
<iframe width="560" height="315" src="https://www.youtube.com/embed/JfHXbPv9cUg" frameborder="0" allowfullscreen></iframe>
</div>
</p>
<div id="more1" align="center" title="View More">
<img src="http://www.blackballad.co.uk/wp-content/uploads/2016/10/drop.png" width="20px" height="20px">
</div>

</div>

</body>

<?php get_footer(); ?>

Answer

Try do_shortcode()

https://developer.wordpress.org/reference/functions/do_shortcode/

For youtube

echo do_shortcode( '[embed]https://www.youtube.com/user/bluehost?v=zQ-eL7zH6rQ[/embed]' );
Comments