Embed Twitch error and update

  • Unknown's avatar

    I think WordPress should update the Twitch embed. i did a hook to update it.

    Now the iframe src url need your website domain: &parent=mywebsiteurl.com
    No https or https, no dot, no slash, only domain and extension.

    // at top of php plugin
    if ( !defined( ‘SITE_URL’ ) ) {
    define(‘SITE_URL’, get_site_url());
    }

    // OR ANYWHERE IN PLUGIN
    //$_SERVER[‘SERVER_NAME’]; // PHP
    // get_site_url(); // WORDPRESS

    $re = ‘/https?.*twitch.tv/(w+).*/i’;
    //$subst = ”;
    $subst = ‘
    new Twitch.Player(‘twitch-embed’, {channel: $1}, parent: ”.removeProtocol(SITE_URL).”);’;
    $result = preg_replace($re, $subst, $url);

    // echo removeProtocol($url); // test

    function removeProtocol($url){
    $url = str_replace(‘www.’,”,$url);
    $remove = array(‘http://’,’https://’);
    return str_replace($remove,”,$url);
    }

  • Just so we’re on the same page, is this a proposed update to the WordPress.com Twitch embed (https://wordpress.com/support/videos/twitch-tv-shortcode/)? Or something to do with embedding on a site using the WordPress open-source software (WordPress.org)?

  • The topic ‘Embed Twitch error and update’ is closed to new replies.