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
- 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
1 Answer
Reset to default 0You 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
评论列表(0条)