0

Just looking to see if anyone can help me with a problem I have when returning values within a shortcode.

function youtube_media_shortcode() {


return do_shortcode( '[x_video_embed no_container="true"]<iframe width="560" height="315" src="'.get_field('youtubeurl', 'option').'" frameborder="0" allowfullscreen></iframe>[/x_video_embed]' );
return '<div class="youtube-text">'.get_field('youtubetext', 'option').'</div>';

}

The first part of this returns fine with the video but then it does not seem to return the next line. If I remove the first line then the second one returns fine. I presume it has something to do with the do_shortcode but I have no idea what!

Any help is appreciated :)

0

You shouldn't call return twice in a function, as it isn't supported and only the first return is evaluated.

What you can do is assign the first do_shortcode to a variable and return the variable concatenanted to the second return.

function youtube_media_shortcode() {

    $shortcode_output = do_shortcode( '[x_video_embed no_container="true"]<iframe width="560" height="315" src="'.get_field('youtubeurl', 'option').'" frameborder="0" allowfullscreen></iframe>[/x_video_embed]' );

    return $shortcode_output . '<div class="youtube-text">'.get_field('youtubetext', 'option').'</div>';

}
  • Ahhh I see, that makes sense. I've tested your code as working so thank you very much! – Daniel Kerr Feb 10 '17 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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