我有以下WordPress快捷代码
function wiki_show( $atts ) {
// Attributes
$atts = shortcode_atts(
array(
'name' => '',
'height' => '500',
),
$atts,
'wiki'
);
// Return custom embed code
return '<div><iframe src="https://en.wikipedia.org/wiki/' . '&name=' . $atts['name'] . '" height="' . $atts['height'] . '"/></div> ';
}
add_shortcode( 'wiki', 'wiki_show' );
我在WordPress页面中使用它,例如:
AAAAAAAA
[wiki name="Wolfenstein_3D" height="500"]
BBBBBBB
[wiki name="Nelson_Mandela" height="800"]
CCCCCCCC
问题是在第一个iframe之后,没有显示任何内容(甚至不是BBBB ....是第一个iframe之后)
)如果我更改了短代码以标记一些" foo"而不是" iframe",则正确显示了所有代码。
如果我手动嵌入2个iframe(没有快捷代码),则可以正常工作。
如何使短码工作?我在做什么错?
(*信用:此代码从:https://generatewp.com/shortcodes/?clone=video-embed-shortcode)
<iframe>
元素不是自闭合元素。您应该将其更改为
return '<div><iframe […]></iframe></div>';
还查看HTML验证器,它将遇到此问题。; - )