2016-10-23 52 views
0

我爲我的wordpress網站上的一個頁面創建了一個新的模板頁面,因爲我只想在該頁面上放置一些文本和YouTube視頻。據我所知,Wordpress不接受在代碼中嵌入YouTube視頻,您必須使用YouTube Player API。但說實話,我不清楚如何將它應用到我當前的代碼中。任何人都可以幫忙,或提供一些建議嗎?如何在WordPress模板頁面中嵌入YouTube視頻?

<?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(); ?> 

回答

1

嘗試do_shortcode()

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

對於YouTube

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

我試圖嵌入在模板的原始代碼的鏈接,而不是在WordPress管理的說明..你知道我能做到嗎? –

+0

是的,將您的模板放置在您的模板中,您希望顯示YouTube視頻。如果你需要在帖子中顯示它,我相信你需要把它放在'for'或'while'循環中。檢查WordPress文檔。 – LegenJerry

+0

我簡直就是把 <?php echo do_shortcode('[embed] https://www.youtube.com/user/bluehost?v=zQ-eL7zH6rQ [/ embed]'); ?> 就在我的原始代碼的頂部&仍然絕對沒有。這裏肯定有些事情是錯的。看看你自己http://www.blackballad.co.uk/crowdfunding/ –

相關問題