我制作的自定义短代码被强制到小部件容器外部的小部件顶部。知道为什么吗?这是我的代码。。。
function nktmediaplayer_func($atts) {
extract(shortcode_atts(array(
\'id\' => rand(1, 900),
\'language\' => \'en\',
\'playlist\' => \'no\',
\'media\' => \'3381\',
\'height\' => \'480\',
\'width\' => \'640\',
\'style\' => \'single\'
), $atts));
?>
<div id="player_<?php echo $id; ?>" class="video_player"><a href="http://www.adobe.com/products/flashplayer/">Get the Flash Player</a> to see this player.</div>
<script type="text/javascript" src="http://kadampa.org/embed/apps/jwplayer.js"></script>
<script type="text/javascript">
jwplayer("player_<?php echo $id; ?>").setup({
flashplayer: "http://kadampa.org/embed/apps/player.swf",
playlistfile: "http://kadampa.org/<?php echo $language; ?>/api/video/<?php if ( \'playlist\' == \'yes\' ) echo \'playlist/\'; ?><?php echo $media; ?>/desc",
height: "<?php echo $height; ?>",
width: "<?php echo $width; ?>",
config: "http://kadampa.org/embed/config/<?php echo $style; ?>.xml"
});
</script>
<?php
}
add_shortcode(\'nkt_mediaplayer\', \'nktmediaplayer_func\', 10);
最合适的回答,由SO网友:sanchothefat 整理而成
对于短代码,您必须返回输出,以便在短代码出现的地方写出。
要么将HTML转换为PHP字符串,而不是打破PHP标记,要么可以使用PHPs输出缓冲方法,如下所示:
ob_start();
?>
<div id="player_<?php echo $id; ?>" class="video_player"><a href="http://www.adobe.com/products/flashplayer/">Get the Flash Player</a> to see this player.</div>
<script type="text/javascript" src="http://kadampa.org/embed/apps/jwplayer.js"></script>
<script type="text/javascript">
jwplayer("player_<?php echo $id; ?>").setup({
flashplayer: "http://kadampa.org/embed/apps/player.swf",
playlistfile: "http://kadampa.org/<?php echo $language; ?>/api/video/<?php if ( \'playlist\' == \'yes\' ) echo \'playlist/\'; ?><?php echo $media; ?>/desc",
height: "<?php echo $height; ?>",
width: "<?php echo $width; ?>",
config: "http://kadampa.org/embed/config/<?php echo $style; ?>.xml"
});
</script>
<?php
$output = ob_get_contents();
ob_end_clean();
return $output;