Skip to content

Instantly share code, notes, and snippets.

@dobsondev
Created March 25, 2014 18:00
Show Gist options
  • Save dobsondev/9767504 to your computer and use it in GitHub Desktop.
Save dobsondev/9767504 to your computer and use it in GitHub Desktop.
Shortcode for Embedding a Twitch.tv Stream Chat - Used in DobsonDev Shortcodes Plugin for WordPress
<?php
/* Adds a shortcode to embed a Twitch Stream's chat */
function dobson_embed_twitch_chat($atts) {
extract(shortcode_atts(array(
'username' => "Invalid Username",
'width' => "350",
'height' => "500",
), $atts));
$source_headers = @get_headers("http://twitch.tv/chat/embed?channel=" . $username . "&popout_chat=true");
if (strpos($source_headers[0], '404 Not Found')) {
return '<p> Invalid Twitch channel name. Please check your username and channel settings on Twitch to make '
. 'sure they are setup correctly. </p>';
} else {
return '<iframe frameborder="0" scrolling="no" id="chat_embed" src="http://twitch.tv/chat/embed?channel='
. $username . '&popout_chat=true" height="' . $height . '" width="' . $width . '"></iframe>';
}
}
add_shortcode('embedTwitchChat', 'dobson_embed_twitch_chat');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment