0

我正在使用 iframe Wordpress 插件。它需要如下语法(简码): [iframe src="http://www.youtube.com/embed/A3PDXmYoF5U" width="100%" height="480"]

我想获取 meta_key 中的信息并通过 do_shortcode 函数传入 Wordpress 模板。我正在使用的代码如下:

if ( get_post_meta($post->ID, 'youtube-video', true) ){
  $youtube_video = get_post_meta($post->ID, 'youtube-video', true);
  echo do_shortcode('[iframe src="' . $youtube_video . '" width="100%" height="480"]');
}

但它不起作用。我认为问题是由于 get_post_meta 函数返回一个值。如何解决这个问题呢?

编辑:请注意,如果我以这种方式修改上面的代码:

if ( get_post_meta($post->ID, 'youtube-video', true) ){
  $youtube_video = get_post_meta($post->ID, 'youtube-video', true);
  echo $youtube_video;
  echo do_shortcode('[iframe src="' . $youtube_video . '" width="100%" height="480"]');
}

它打印 url ( http://www.youtube.com/embed/A3PDXmYoF5U ) 但最后一个 echo 不打印任何内容。

4

0 回答 0