<?php
function youtube_api__wp_enqueue_scripts() {
wp_enqueue_script( 'yt-player-api', 'http://www.youtube.com/player_api', array (), false, true );
}
add_action( 'wp_enqueue_scripts', 'youtube_api__wp_enqueue_scripts' );
function youtube_api__wp_footer() {
if ( wp_script_is( 'yt-player-api', 'done' ) ) {
$player_id = 'abcxyz';
$video_id = '123456';
?>
<script id="yt-player-api-ready" type="text/javascript">
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player("<?php echo $player_id ?>", {
height: "315",
width: "560",
videoId: "<?php echo $video_id ?>"
});
}
</script>
<?php
}
}
add_action( 'wp_footer', 'youtube_api__wp_footer', 20 );
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.