当用户输入id时,我试图编写一个显示youtube视频的短代码。
例如,我的短代码如下所示:
[youtube id="SP6abPzY300GVnc8pGr8qqd6U0eABNPHf6"]
在前端,这将显示youtube视频在我的博客页面。
到目前为止,我的代码是:
function wp_youtube_video($atts) {
extract(shortcode_atts(array(
'id' => ''
), $atts));
return $id;
}
add_shortcode('youtube', 'wp_youtube_video');发布于 2013-09-13 14:06:21
如果您将return $id更改为return $atts['id'],则返回return $atts['id'] ID。但是,您需要将该ID与YouTube视频嵌入代码关联,以使其正确显示。就像这样也许..。
function wp_youtube_video($atts) {
extract(shortcode_atts(array(
'id' => ''
), $atts));
return '<iframe title="YouTube video player" class="youtube-player" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/'.$atts['id'].'" frameborder="0" allowFullScreen></iframe>';
}
add_shortcode('youtube', 'wp_youtube_video');https://stackoverflow.com/questions/18788008
复制相似问题