0

I know i am missing something simple. I just want to display this iframe if $video-code exists. Can anyone see what is wrong with this? working in wordpress. error is on the echo line. i've also tried adding .'$video-code'. into the url.

it is displaying the iframe correctly, but the variable is displaying as text in the url. if i call the variable elsewhere in the page without the If statement, it displays correctly.

THANKS for any help!

<?php
$key = 'video-code';
$themeta = get_post_meta($post->ID, $key, TRUE);
if($themeta != '') {
echo '<iframe id="player" width="560" height="315" frameborder="2"     src="http://www.youtube.com/embed/$video-code" ></iframe>';
}?>
1
  • your variable is $key not $video-code, so it should be '.$key.' as php variables are not parsed inside single quotes. Commented Jul 24, 2013 at 3:31

1 Answer 1

1

You can concatenate your $key, like so:

echo '<iframe id="player" width="560" height="315" frameborder="2" 
src="http://www.youtube.com/embed/' . $key . '" ></iframe>';
Sign up to request clarification or add additional context in comments.

2 Comments

hmmm.. it's not working :( the whole thing displays as this code " 0" >" code here is my code code <?php $key = 'door-time'; $themeta = get_post_meta($post->ID, $key, TRUE); if($themeta != '') { echo '<iframe id="player" width="560" height="315" frameborder="2" src="youtube.com/embed' . $door-time . '" ></iframe>'; }?>code
Where are getting the ID for the video? You need to pass the ID to $key variable. Also, you're using $door-time inside your iframe code. It should be $key. (I tested this before posting and it did actually work. Here's an example: codepad.org/rfxcmNss)

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.