Twitch Conditional – A WordPress Plugin for Twitch Streamers

WordPress

I love Twitch. I actually spend my work day with one browser dedicated to Twitch, and subscribe to MrHappy’s daily Stream. So when rumors surfaced a few years ago their API, of course I wanted a way to interface with that API.

In doing research, I realized that a lot of streamers don’t have real websites. A few of the top ones do, but I think it’s because the automation between Twitch and a true website is “iffy” – you have to manually update every time your stream goes live, and that takes precious time away from interacting with the community (and actually streaming).

What if there was a way to automatically update your website to let people know that you were streaming – and that would turn itself off once the stream was over.

Twitch Conditional

I love the way WordPress handles conditional statements; there’s very specific “if” statements built into the core, and it lets you check for any number of flags to be set – is it a Category? is it a Tag? is it page two of some random archive? There’s a conditional for that. So what if there was a way to work with Twitch the same way?

The Twitch Conditional WordPress plugin allows you to see when you – or your favorite streamer – is online, and hides/shows content accordingly.

This plugin takes one variables in the options panel: a Client ID. You can get that from your profile: https://www.twitch.tv/settings/connections. Log in, generate a client ID, and then put it in the options pane. That’s the only set up you need.

When you’re developing your website, you can use something similar to this:

<?php if (twitch_is_live('username')) { ?>
    <p><a href="##twitch_url##">Currently Streaming Live!</a></p>
<?php } else { ?>
    <p>This Twitch user is currently offline!</p>
<?php } ?>

Breaking that down: If USERNAME is live, display a link to the twitch stream. If not, display some text that says the user is offline.

You could get really in-depth, hiding and showing entire sections of the site, embedding your twitch stream into the section so that it shows up when you go online. Or you could do a simple offline/online check with a special icon.  The possibilities are endless.

One day I’ll edit this plugin to have shortcodes – for now, the developer piece is what I was really wanted to get finished.

You can download the plugin here, on Github: https://github.com/thatmitchcanter/twitch-conditional