这是未经测试的,但在我看来,您可以简单地替换:
$audio = "<audio src=\'$url\' controls autoplay loop></audio>";
使用
$autoplay = is_singular( \'your_post_type\' ) ? \'autoplay\' : \'\';
$audio = "<audio src=\'$url\' controls $autoplay loop></audio>";
一、 e.我们使用
$autoplay 变量来存储
autoplay 属性,并且如果当前页面是文章类型的单个页面(
your_post_type), 然后我们将变量值设置为
autoplay.
但是如果你想add/enable 音频播放器仅在自定义帖子类型页面上显示,然后只需更改is_singular() 在您的代码中is_singular( \'your_post_type\' ). 类似于:
function wpse_67108_autplay_music( $content )
{
if ( ! is_singular( \'your_post_type\' ) )
{
return $content;
}
// ... the rest of your code here.
}