How to return html as a string from php for WordPress

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

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

  • 1
    There's nothing WordPress specific about returning strings. Strings are a basic feature of PHP and work the same everywhere. Oct 11, 2019 at 0:14

1 Answer 1


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>';
  • its works, but plugin not working javascript error. Oct 12, 2019 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.