When I use my code below inside the WP loop I get to see both the player and the url. Needless to say, I only want to see the player.

How to correct my code so it'll only show the player?


My code is as follows:

$fes_featured_audio = get_post_meta( get_the_ID(), 'upload_featured_audio', true ); // custom upload field

if (is_array($fes_featured_audio)) {    
    foreach($fes_featured_audio as $key=>$val){ 

        if ( $key < 1) {
            $url_audio = wp_get_attachment_url( $val ); 
        } else {
            $url_audio_playlist   = explode(',', get_attached_media( 'audio', $val ) ); 


$attr = array(
    'src'      => strip_tags($url_audio),
    'loop'     => 'true',
    'autoplay' => '',
    'preload'  => 'auto',

if ( $key < 1) {
    echo '<div class="audio-player" itemprop="audio">' . wp_audio_shortcode( $attr ) . ' </div>';
} else {
    echo do_shortcode('[playlist ids="'.$url_audio_playlist.'"]');

closed as off-topic by fuxia Jan 20 '16 at 14:24

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • core.trac.wordpress.org/browser/trunk/src/wp-includes/… and core.trac.wordpress.org/browser/trunk/src/wp-includes/… both seem to return html. Can you narrow it down to which line produces extra output? – jgraup Jan 18 '16 at 16:57
  • I'm afraid I don't know which line is line is adding the extra output. :( – kiarashi Jan 18 '16 at 17:35
  • It's super easy, you should comment out lines from the bottom up until the output stops. That's how you find out what is causing it. Then you narrow in on that specific line. – jgraup Jan 18 '16 at 18:09
  • <div class="audio-player" itemprop="audio">' . wp_audio_shortcode( $attr ) . ' </div> outputs both the player and extra url. If I remove this line, both are gone. I think I'm close to finding the cause actually. I used strip_tags($url_audio) but the extra html link code that is automatically added because it's an url, doesn't get stripped. I also tried html_entity_decode but that didn't work either. Do you perhaps have any other ideas? – kiarashi Jan 18 '16 at 18:29
  • Try 'src' => esc_attr( esc_url( strip_tags( $url_audio ) ) ), – jgraup Jan 18 '16 at 18:53

Nothing wrong with the function above. Turns out my function was placed inside an a href tag.

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