我需要帮助创建 Wordpress 函数以在后期编辑器中生成短代码 [youtube-id=ID]
输出以下包含 ID
值的 html 代码:
<iframe width="420" height="315" src="https://www.youtube.com/embed/ID?rel=0" frameborder="0" allowfullscreen></iframe>
最佳答案
在你的 functions.php 中
function YouTubeID($atts, $content = null) {
extract(shortcode_atts(array('id'=>''), $atts));
return '<iframe width="420" height="315" src="https://www.youtube.com/embed/'.$id.'?rel=0" frameborder="0" allowfullscreen></iframe>';
}
add_shortcode('youtube', 'YouTubeID');
无论您想要视频的哪个位置,短代码都将是:
[youtube id="THE_ID"]
关于php - 用于自定义 html 输出的 Wordpress 编辑器简码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35608773/