最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I embed a YouTube video in a WordPress template page? - Stack Overflow

programmeradmin1浏览0评论

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. What can I try next?

<?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=".3.7/css/bootstrap.min.css">
  <script src=".10.2.js"></script>
  <script src=".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="; frameborder="0" allowfullscreen></iframe>
      </div>
    </p>
   <div id="more1" align="center" title="View More">
     <img src=".png" width="20px" height="20px">
   </div>

</div>

</body>

<?php get_footer(); ?>

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. What can I try next?

<?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./bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://code.jquery./jquery-1.10.2.js"></script>
  <script src="https://ajax.googleapis./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./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(); ?>
Share Improve this question edited Mar 27, 2021 at 10:04 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Oct 23, 2016 at 17:38 T.DoeT.Doe 2,0358 gold badges28 silver badges48 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Try do_shortcode()

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

For youtube

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

You can do it like this:

global $wp_embed;
echo $wp_embed->run_shortcode( '[embed]https://vimeo./51589652[/embed]' );
发布评论

评论列表(0)

  1. 暂无评论