如何在WordPress模板页面中嵌入YouTube视频?

4

我为我的WordPress网站上的某个页面创建了一个新的模板页面,因为在那个页面上我只想要一些文字和一个YouTube视频。据我所知,WordPress不接受在代码中简单嵌入YouTube视频,你必须使用YouTube Player API

但说实话,我不太清楚如何将其应用到我的当前代码中。接下来我该尝试什么?

<?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(); ?>
3个回答

5

我正在尝试将链接嵌入模板的原始代码中,而不是在WordPress管理界面中的描述... 你知道我该如何实现吗? - T.Doe
你需要用想要展示的视频链接替换掉那个YouTube链接。但是,是的,那应该可以工作。 - LegenJerry
你可能想把那段代码放在video-container1 div里面。 - LegenJerry
你确定你发布的链接使用了一个模板吗?或者你在原始帖子中发布的那个特定模板? - LegenJerry
WordPress媒体上传器允许用户上传图像、文档、视频和音频,并在帖子上直接创建所选媒体文件的返回引用链接。https://www.wpblog.com/embed-wordpress-videos-audios-images/ - Owais Alam
显示剩余2条评论

1
只是评论一下,2022年已经不能使用所接受的答案了。由于嵌入式短代码似乎无法正常运行,我们需要进行更新。

0
你可以这样做:
global $wp_embed;
echo $wp_embed->run_shortcode( '[embed]https://vimeo.com/51589652[/embed]' );

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接