【发布时间】:2016-02-25 01:31:56
【问题描述】:
我需要帮助创建 Wordpress 函数以在帖子编辑器中生成短代码 [youtube-id=ID] 输出以下包含 ID 值的 html 代码:
<iframe width="420" height="315" src="https://www.youtube.com/embed/ID?rel=0" frameborder="0" allowfullscreen></iframe>
【问题讨论】:
我需要帮助创建 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"]
【讨论】:
试试这个
function my_amazing_shortcode_handler($args)
{
$args=shortcode_atts(array('id' => 'some_default_id'), $args);
return '<iframe width="420" height="315" src="https://www.youtube.com/embed/' . $args['id'] . '?rel=0" frameborder="0" allowfullscreen></iframe>';
}
add_shortcode('youtube_iframe', 'my_amazing_shortcode_handler');
像[youtube_iframe id='some_id']一样使用
【讨论】: