plugin development - How to return html as a string from php for WordPress

How to return html as a string from php for WordPressfunction play_audio($atts){$a = shortcode_atts( array('url

How to return html as a string from php for WordPress

function play_audio($atts){
    $a = shortcode_atts( array(
        'url' => ''
    ), $atts );
    wp_enqueue_script('player');
    wp_enqueue_script('play_script');
    wp_enqueue_style('progress_bar');
    return '<div class="mediPlayer">
    <audio class="listen" preload="none" data-size="250" src=" . $a[url] . "></audio>
</div>
</div>';
}
add_shortcode( 'playaudio', 'play_audio' );

src=" . $a[url] . "> I'm confuse with this part its not return url

How to return html as a string from php for WordPress

function play_audio($atts){
    $a = shortcode_atts( array(
        'url' => ''
    ), $atts );
    wp_enqueue_script('player');
    wp_enqueue_script('play_script');
    wp_enqueue_style('progress_bar');
    return '<div class="mediPlayer">
    <audio class="listen" preload="none" data-size="250" src=" . $a[url] . "></audio>
</div>
</div>';
}
add_shortcode( 'playaudio', 'play_audio' );

src=" . $a[url] . "> I'm confuse with this part its not return url

Share Improve this question edited Oct 11, 2019 at 0:13 Jacob Peattie 44.2k10 gold badges50 silver badges64 bronze badges asked Oct 10, 2019 at 19:25 Shaif ShahinShaif Shahin 331 silver badge4 bronze badges 1
  • 1 There's nothing WordPress specific about returning strings. Strings are a basic feature of PHP and work the same everywhere. – Jacob Peattie Commented Oct 11, 2019 at 0:14
Add a comment  | 

1 Answer 1

Reset to default 0

You are missing multiple single quotes around $a[url], so after src=" there should be a ' and after $a[url] there should be another single quote, and you also need to quote the array key, so the whole return line should be

return '<audio class="listen" preload="none" data-size="250" src="' . $a['url'] . '"></audio></div></div>';

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745090880a4610687.html

相关推荐

  • plugin development - How to return html as a string from php for WordPress

    How to return html as a string from php for WordPressfunction play_audio($atts){$a = shortcode_atts( array('url

    17小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信