I am trying to embed a Twitch.tv live stream into an echo (so that the stream shows when online, but shows text when offline). This is my first learning experience with echos. I have it working so long as I just have text showing, but when I insert the shortcode, an iframe, or even just html to display an image I get a parse error.
Here is the code that I want to insert into the ONLINE INFO of the echo:
<?php echo do_shortcode('[embedTwitch username="CHANNELNAME" width="100%"]'); ?>
Here is the code I am trying to insert it into (specifically into the ONLINE INFO area):
<?php $streamChannel = "CHANNELNAME";
$json_array = json_decode(file_get_contents("https://api.twitch.tv/kraken/streams.json?channel=$streamChannel"), true);
if(isset($json_array['streams'][0]['channel'])) {
echo "<div id='streamonline'>ONLINE INFO</div></div>";
} else {
echo "<div id='streamoffline'>OFFLINE INFO</div>";
}
?>
Both work independently of the other, but when I try to insert the stream into the variable online/offline code I get an error. Here is what I am doing that gets the error:
<?php $streamChannel = "CHANNELNAME";
$json_array = json_decode(file_get_contents("https://api.twitch.tv/kraken/streams.json?channel=$streamChannel"), true);
if(isset($json_array['streams'][0]['channel'])) {
echo "<div id='streamonline'><?php echo do_shortcode('[embedTwitch username="CHANNELNAME" width="100%"]'); ?></div></div>";
} else {
echo "<div id='streamoffline'>OFFLINE INFO</div>";
}
?>