Jos haluat upottaa Twitch-leikkeitä WordPress-sivustolle, se onnistuu oheisen shortcoden avulla. Kun lisäät tämän shortcoden teeman functions.php-tiedostoon, saat käyttöön twitchclip-shortcoden, joka tekee leikkeen nimen perusteella Twitchin ohjeiden mukaisen iframe-upotuksen.
add_shortcode( 'twitchclip', 'twitchclip' );
/**
* Shortcode Twitch-leikkeiden upotusta varten.
*
* @param array $atts Parametrit: clip on leikkeen tunnus, width upotuksen
* leveys, height upotuksen korkeus. Leveyden oletusarvo on 640, korkeuden
* 360 pikseliä.
*
* @return string Upotus-iframe.
*/
function twitchclip( $atts ) {
$atts = shortcode_atts(
array(
'clip' => false,
'width' => 640,
'height' => 360,
),
$atts,
'twitchclip'
);
if ( ! $atts['clip'] ) {
return '';
}
return <<<EOTWITCH
<iframe
src="https://clips.twitch.tv/embed?clip={$atts['clip']}&parent={$_SERVER['SERVER_NAME']}"
height="{$atts['height']}"
width="{$atts['width']}"
frameborder="0"
scrolling="no"
allowfullscreen="yes">
</iframe>
EOTWITCH;
}